taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

Insane memory allocation in -run! and -run-kv! #102

Closed leiffoged closed 6 years ago

leiffoged commented 7 years ago

I'm using nippy extensively in a project. A huge source of garbage is coming from functions like write-vec (I'm serializing a lot of small vectors). The issue seems to be -run! and -run-kv!, which are implemented as macros.

Because the function expression is inlined within the function passed to reduce, this allocates a new closure on each iteration of reduce / reduce-kv.

Suggestion (easy): Make -run! / -run-kv! functions instead of macros (or bind the passed in function to a variable in the macros), which will eliminate the allocation on for each element (in favor of a single closure allocated per vector/map/etc).

If you'll accept a pull request, I'd be happy to write something up.

Thanks!