On Monday, June 22, 2015 at 2:45:19 PM UTC-5, marc fawzi wrote: > Idioms aside, what is the material benefit of using volatile over a locally > scoped atom? I googled a bit and it seems that it has less concurrency > guarantees and thus less overhead in Clojure but for ClojureScript is it > really any lighter than an atom? > > Sent from my iPhone
In ClojureScript the performance difference is probably marginal. (In Clojure the difference is more pronounced.) Concretely, the Volatile object has only one property (state) instead of the Atom's four (state, metadata, validator function, and watchers) and the vswap! and vreset! macro and function do not have any conditionals for validation or watcher notification. Notice this means volatiles do not support metadata, validators, or watchers. In most situations the advanced-compiled output for vreset! is an inline property set (e.g. my_volatile.state = newval), i.e. the function call is eliminated. This is less likely for an atom's reset! because the compiler may not be able to eliminate the validation and watcher notification code. However this is unlikely to make any difference in real-world usage. Volatiles are as close as one can get to a platform-native mutable local variable in clojure and clojurescript right now. -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
