Fork me on GitHub
#clojure-dev
<
2019-07-16
>
andy.fingerhut22:07:59

I'm using Clojure/Java 1.10.1 right now, and I might be seeing some performance degradation when using Clojure sets as map keys or set elements, where it seems much slower when using those vs. using integers as keys/elements, even though the sets being used as keys/elements have (identical? x y) = true when they are equal, so I would expect (= x y) to return true as fast as (identical? x y) to return true. Does this ring a bell for anyone in the implementation? I will poke around a bit more to see if I can find something, and report here.

andy.fingerhut22:07:19

Hmm. Maybe because APersistentSet has equiv() implementation that does not check for identical using == as a fast path?

andy.fingerhut22:07:57

Huh, I guess I assumed that would be done there.

andy.fingerhut22:07:47

APersistentMap equiv() also has no such if-identical-return-true-quickly fast path.

andy.fingerhut22:07:06

APersistentVector equiv() does have such a fast path

alexmiller22:07:34

nothing has changed with any of this recently afaik - what do you mean by "degradation"?

alexmiller22:07:12

can you share what you're actually testing? Util.equiv(Object, Object) has the identity check

andy.fingerhut22:07:32

I'm doing some more investigation to firm up my claims here, or likely figure out that I'm imagining things. I have some code that I think is running quite quickly when I have lots of sets and maps containing longs as set elements / map keys, but I think the same code is noticeably slower when using IPersistentSet's of longs as set elements / map keys.

hiredman22:07:48

there were some mailing list posts for many years ago about performance of small collections as keys in maps, I believe inside instaparse

hiredman22:07:37

and I don't entirely recall, but I think the gist of it was something like, computing the hash codes for small collections up front would perform better, but clojure generally computes in on demand and caches it

hiredman22:07:15

that may predate the hasheq stuff even, so maybe too old

hiredman23:07:45

(and of course last edited by @andy.fingerhut)

😂 1
andy.fingerhut23:07:38

Yep, I recall those events. Fun perf debugging! 🙂

andy.fingerhut23:07:06

I believe this is different than that.

ghadi23:07:21

I wonder how SipHash and other more recent non-cryptographic hashes perform