better collections through code generation

860 views
Skip to first unread message

Zach Tellman

unread,
Aug 25, 2014, 8:07:57 PM8/25/14
to cloju...@googlegroups.com
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.

David Pollak

unread,
Aug 25, 2014, 8:22:01 PM8/25/14
to cloju...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/d/optout.



--
Lift, the simply functional web framework http://liftweb.net

Rich Hickey

unread,
Aug 27, 2014, 7:23:52 AM8/27/14
to cloju...@googlegroups.com
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

Brandon Bloom

unread,
Aug 28, 2014, 8:34:07 PM8/28/14
to cloju...@googlegroups.com
I'm curious if there is any interest/benefit for similar small maps or sets...


On Monday, August 25, 2014 8:07:57 PM UTC-4, Zach Tellman wrote:

Mikera

unread,
Aug 28, 2014, 10:39:04 PM8/28/14
to cloju...@googlegroups.com
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....)

Jozef Wagner

unread,
Aug 29, 2014, 2:45:23 AM8/29/14
to cloju...@googlegroups.com

Zach Tellman

unread,
Aug 31, 2014, 11:31:46 PM8/31/14
to cloju...@googlegroups.com
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.

Zach Tellman

unread,
Sep 2, 2014, 2:14:05 PM9/2/14
to cloju...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages