[CLJS-453] ArrayVector for small vectors Created: 04/Jan/13 Updated: 04/Jan/13 |
|
| Status: | Open |
| Project: | ClojureScript |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Enhancement | Priority: | Minor |
| Reporter: | Jozef Wagner | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
master cljs, chrome |
||
| Attachments: |
|
| Description |
|
Just like we have an ArrayMap for small maps, I propose to have an ArrayVector for small vectors. Use cases:
ArrayVector has 100x faster vector creation compared to PersistentVector. Example of such destructuring: (defn foo [a b]
[(+ a b) (- a b) (* a b)])
(defn bar []
(let [[plus minus times] ^ArrayVector (foo 1 2)]
(str "bla bla" plus "blaah" minus)))
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 to PersistentVector for large vectors. ArrayVector implementation can also be found at array-vec branch at https://github.com/wagjo/clojurescript/tree/array-vec |
| Comments |
| Comment by David Nolen [ 04/Jan/13 4:54 PM ] |
|
Thanks! This interesting, it would be helpful to see a more comprehensive set of benchmarks on jsperf.com. |