The common case in hash map lookup for keywords _that finds a matching key
in the map_ is:

(a) hash the keyword (fast, because it is cached)
(b) use the hash code value to walk one or more nodes in a tree to reach a
leaf, where there can be a single value, or a linked list of multiple
colliding values (the colliding value case should be quite rare in Clojure
1.6.0 and later)
(c) now compare the searched-for keyword against the key in the map, which
by the assumption in the first sentence is =.  If two keywords are =, then
they are also identical, and so = takes the fastest possible path of
returning true because they are identical.

The common case for looking up a keyword that does not find a matching key
in the map is (a), then (b), then falling out of the tree and not comparing
against any other value, so even faster than the above.

Andy


On Sat, Oct 11, 2014 at 5:28 PM, Mike Rodriguez <mjr4...@gmail.com> wrote:

> To the point (b) it seems that this posts is saying the clj's = will not
> be faster for keyword than string since the runtime type checking overhead
> is where most time is spent. So the identity part of keyword equals doesn't
> show its benefit here (unless these were long strings vs long keywords I
> suspect, but this is uncommon).
>
> The hash code calculation stuff would add performance value though.
>
> I'm just saying I don't see how point (b) is adding performance gains in
> the context of what else I've read here.
>
> If the compiler (doesn't seem always possible) or map impl's or something
> is smart enough to not use clj's basic = impl on keywords though and use
> its equals directly instead, that'd sound like a win.
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to