-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance #7
Comments
These are great suggestions -- i haven't used clj-fast before. As for id+attrs, maybe i could calculate a keyword based on it and use that instead...but that feels like just implementing a second layer of hashing for map keys. Gotta think about it more... |
Thank you 🙏 (deftype IdAttr [id attr ^:unsynchronized-mutable ^int _hasheq]
java.lang.Object
clojure.lang.ILookup
clojure.lang.IHashEq
clojure.lang.IKeywordLookup
clojure.lang.IPersistentMap
java.util.Map
(equals [this that]
(boolean
(or (identical? this that)
(and (instance? IdAttr that)
(= id (.id ^IdAttr that))
(= attr (.attr ^IdAttr that))))))
(equiv
[this that]
(boolean
(or (identical? this that)
(and (instance? IdAttr that)
(= id (.id ^IdAttr that))
(= attr (.attr ^IdAttr that))))))
(valAt
[_ k else]
(condp identical? k
:id id
:attr attr
else))
(valAt [this k] (.valAt this k nil))
(get [this k] (.valAt this k))
(seq [_] (seq [id attr]))
(hasheq [_]
(let [hq _hasheq]
(if (zero? hq)
(let [h (int
(bit-xor
968592507
(Murmur3/mixCollHash (unchecked-add-int (int (Util/hasheq id)) (int (Util/hasheq attr))) (int 2))))]
(set! _hasheq h)
h)
hq)))) Which works (really works, tests pass and all), but no one wants to look at or maintain |
That is really neat, i'll try it when i get the chance. Maybe one way to avoid the complexity and maintenance burden would be to just provide a way to supply an id+attr constructor function to |
On the other hand, when you open that door someone will use it to blow their own foot off. |
That is true...and this id+attr thing would be a weird internal detail to expose, now that i think of it. |
Hello,
I have a bad habit of finding cool project and looking under the hood for performance lying on the floor.
After doing some poking around and running benchmarks I can share some findings:
id+attrs
inleft-activate-memory-node
. Every time collections are looked up as keys in a map it forces an equality check that walks both of them. This causes an otherwise disproportionate amount of CPU to be wasted onassoc
ing. I'm not sure about the best way to mitigate that. If you find a way to representid+attr
as a keyword it would probably help, but will surely take some thinking. There's about 15% CPU left there after the previous optimizationI'll be happy to keep digging if you're interested.
Keep up the amazing work :)
The text was updated successfully, but these errors were encountered: