ArrayVector for small vectors
Description
Environment
master cljs, chrome
Attachments
Activity
David Nolen December 2, 2014 at 12:19 PM
I believe Zach Tellman's proposal for tuples will likely land and be the approach we adopt.
David Nolen November 19, 2013 at 5:03 PM
We're not going to add special cases like that. It's in the works to add more inference to the compiler so that protocol backed fns will inline more simply with less hinting.
Jozef Wagner November 19, 2013 at 9:47 AM
Thank you. I've updated the benchmarks which confirm that PV are now on par with AV in terms of creation and conjoining. The lookup time optimization boils down to this core, which can be changed to support PVs too.
David Nolen November 17, 2013 at 6:00 PM
PersistentVector creation time is now nearly as fast as ArrayVector in master. -nth
is still a bit slower under V8, but surprisingly under WebKit Nightly PVs appear to outperform AVs here.
David Nolen November 17, 2013 at 5:38 AM
I'm not excited about more type hints I've landed a performance improvement for conj, PVs run circles around AVs now. PV construction time can be made competitive with AV construction time trivially by making the compiler inline instantiation.
This leaves lookup time, I wonder if we could close the gap? It would be nice to rerun the benchmarks after we land some more PV enhancements.
Just like we have an
ArrayMap
for small maps, I propose to have anArrayVector
for small vectors.Use cases:
pair of values, e.g. coordinates, triples and other tuple values
returning multiple values from a function and subsequent destructuring in a caller fn
ArrayVector
has 100x faster vector creation compared toPersistentVector
.With an
^ArrayVector
hint, it offers more than 10x faster destructuring. Without it, it is still about 40% faster.Example of such destructuring:
I've attached a patch with complete implementation of such vector, supporting all basic functionalities as well as transients. This patch also replaces default vector implementation with
ArrayVector
, falling back toPersistentVector
for large vectors.ArrayVector implementation can also be found at array-vec branch at https://github.com/wagjo/clojurescript/tree/array-vec