| better collections through code generation | Zach Tellman | 25/08/14 17:07 | At Clojure/West I spoke with Rich over lunch, and he mentioned that he was perfectly willing to consider putting something like clj-tuple [1] in the core implementation, as long as it was written in Java. Towards this end, I made a thing [2]. It uses code that looks like this: to generate code like this: There are benchmarks that demonstrate sizable performance gains relative to both lists and generic vectors, except in the case of conj'ing onto a 5-arity fixed size vector, where it has to spill over into a generic vector. This cost is quite small, though, and I feel is more than made up for everywhere else. I intend to make something similar for sets and maps, but first I'd like to make absolutely certain that this can make it into the core implementation. Feedback from the JIRA gatekeepers would be greatly appreciated. |
| Re: better collections through code generation | David Pollak | 25/08/14 17:22 | I'm having flashbacks... https://github.com/scala/scala/blob/2.11.x/src/library/scala/Product1.scala -- -- |
| Re: better collections through code generation | Rich Hickey | 27/08/14 04:23 | Yes, still interested, awesome - thanks! It would be best if the PV1-4 end up as nested classes in a single class/file, and if that class had various factory methods that encapsulated the types. We'll wire it up into vector creation separately, so please keep the patch to the data structures alone. Thanks again, Rich |
| Re: better collections through code generation | Brandon Bloom | 28/08/14 17:34 | I'm curious if there is any interest/benefit for similar small maps or sets...
|
| Re: better collections through code generation | Mikera | 28/08/14 19:39 | Possibly a crazy idea - but how about making the 2-Tuple work as a map entry as well? This could replace clojure.lang.MapEntry..... as well as killing some redundant code I expect it would be a minor performance win (polymorphic inline caching on the JVM really likes it when you re-use the same classes....) |
| Re: better collections through code generation | Jozef Wagner | 28/08/14 23:45 | clj-tuple already does that, https://github.com/ztellman/clj-tuple/blob/d5a11aa3ac576f472ce056d92ddf7ac1e402dc28/src/clj_tuple.clj#L129 |
| Re: better collections through code generation | Zach Tellman | 31/08/14 20:31 | Definitely planning to do this for maps and sets as well, just wanted to make sure I wasn't string-concatenating all this Java for nothing. Work is under way. |
| Re: better collections through code generation | Zach Tellman | 02/09/14 11:14 | Issue opened at http://dev.clojure.org/jira/browse/CLJ-1517 |