Closed joinr closed 4 years ago
It occurs to me there are probably even more efficiencies to be had if the thing you're merging into is a type or record, e.g. you can efficiently construct a new instance very quickly vs. having to do multiple assoc calls. hmm.
I was wondering if I should tackle this use case. Maybe after the big refactor (coming after memoize)
If we enforce the invariant that we have literal maps, with distinct keys, we can merge statically with type hints and avoid iteration costs. I noticed I do this "a lot" in my legacy code, so this refactoring came out during optimization passes. Only works with Associatives
fastest to slowest. Not sure if there's any downside to using .assoc directly over clojure.core/assoc (assumedly clojure.core/assoc is more general, but...)
In this sample, static-merge is ~4.8x faster than clojure.core/merge, and ~3.14x (lol) faster than the
fast-merge
function submitted earlier.