Firstly, I think you over estimate the cost of an if. Ifs are very very fast, especially if you are doing identical? checks (like a case is doing). A simple pointer comparison such as (keyword-identical? :foo :foo) is going to be way faster than a hashmap lookup.
Secondly, ifs are very JIT friendly. Simpler code often means simpler inlining. This could mean that several branches of the if/switch could be removed if the JIT can prove that certain branches cannot be reached. This is much harder to do with a hash map where things could change from one dispatch to the next, and there isn't really a way to communicate immutability to the JVM/JS JITs. On the JVM I've done many tests while building core.async to try to find a better way to do SSA block dispatching. In the end switch (aka case) won every single time. A close second is a small set of nested ifs. Function pointers are just expensive compared ifs and jump tables. Timothy On Tue, Feb 18, 2014 at 5:02 PM, t x <txrev...@gmail.com> wrote: > With apologies for potential stupidity: > > * (get {... } key) is an operation that is O(log n) worst case (if > using Red-Black trees) or O(1) average case (hashing) > > * (get { ... } key) does not have integer/string limitation > > Therefore: why are we not "compiling down to get" ? Are the big-Oh > constants enormous? > > On Tue, Feb 18, 2014 at 3:51 PM, Michał Marczyk > <michal.marc...@gmail.com> wrote: > > Great! First cut at compiling case to switch (when given numbers and > > strings only as tests at the moment, but this can be improved) here: > > > > > https://github.com/michalmarczyk/clojurescript/tree/713-compile-case-to-switch > > > > I'll post more details on the ticket. > > > > Cheers, > > Michał > > > > > > On 18 February 2014 22:38, David Nolen <dnolen.li...@gmail.com> wrote: > >> Due to asm.js some JS engines are starting to compile switch statements > >> where the cases are integers into jump tables. Compiler enhancement that > >> compiles optimizable case expressions to JS switch statements would be a > >> welcome enhancement - http://dev.clojure.org/jira/browse/CLJS-713. > >> > >> David > >> > >> > >> On Tue, Feb 18, 2014 at 4:35 PM, t x <txrev...@gmail.com> wrote: > >>> > >>> Looking at > >>> > https://github.com/clojure/clojurescript/blob/r2156/src/clj/cljs/core.clj#L1144-L1147 > >>> , you win. :-) > >>> > >>> On Tue, Feb 18, 2014 at 1:33 PM, Michał Marczyk > >>> <michal.marc...@gmail.com> wrote: > >>> > On 18 February 2014 22:31, Michał Marczyk <michal.marc...@gmail.com> > >>> > wrote: > >>> >> Actually in ClojureScript case dispatch is O(n), since it's > >>> >> implemented as a macro expanding to cond. > >>> > > >>> > As of release 2156: > >>> > > >>> > > >>> > > https://github.com/clojure/clojurescript/blob/r2156/src/clj/cljs/core.clj#L1119 > >>> > > >>> > -- > >>> > You received this message because you are subscribed to the Google > >>> > Groups "Clojure" group. > >>> > To post to this group, send email to clojure@googlegroups.com > >>> > Note that posts from new members are moderated - please be patient > with > >>> > your first post. > >>> > To unsubscribe from this group, send email to > >>> > clojure+unsubscr...@googlegroups.com > >>> > For more options, visit this group at > >>> > http://groups.google.com/group/clojure?hl=en > >>> > --- > >>> > You received this message because you are subscribed to the Google > >>> > Groups "Clojure" group. > >>> > To unsubscribe from this group and stop receiving emails from it, > send > >>> > an email to clojure+unsubscr...@googlegroups.com. > >>> > For more options, visit https://groups.google.com/groups/opt_out. > >>> > >>> -- > >>> You received this message because you are subscribed to the Google > >>> Groups "Clojure" group. > >>> To post to this group, send email to clojure@googlegroups.com > >>> Note that posts from new members are moderated - please be patient with > >>> your first post. > >>> To unsubscribe from this group, send email to > >>> clojure+unsubscr...@googlegroups.com > >>> For more options, visit this group at > >>> http://groups.google.com/group/clojure?hl=en > >>> --- > >>> You received this message because you are subscribed to the Google > Groups > >>> "Clojure" group. > >>> To unsubscribe from this group and stop receiving emails from it, send > an > >>> email to clojure+unsubscr...@googlegroups.com. > >>> For more options, visit https://groups.google.com/groups/opt_out. > >> > >> > >> -- > >> You received this message because you are subscribed to the Google > >> Groups "Clojure" group. > >> To post to this group, send email to clojure@googlegroups.com > >> Note that posts from new members are moderated - please be patient with > your > >> first post. > >> To unsubscribe from this group, send email to > >> clojure+unsubscr...@googlegroups.com > >> For more options, visit this group at > >> http://groups.google.com/group/clojure?hl=en > >> --- > >> You received this message because you are subscribed to the Google > Groups > >> "Clojure" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an > >> email to clojure+unsubscr...@googlegroups.com. > >> For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > > http://groups.google.com/group/clojure?hl=en > > --- > > You received this message because you are subscribed to the Google > Groups "Clojure" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to clojure+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/groups/opt_out. > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- "One of the main causes of the fall of the Roman Empire was that-lacking zero-they had no way to indicate successful termination of their C programs." (Robert Firth) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.