ClojureScript port of PersistentHashMap

86 views
Skip to first unread message

Michał Marczyk

unread,
Apr 11, 2012, 5:18:47 PM4/11/12
to cloju...@googlegroups.com
Hi,

I've ported PersistentHashMap to ClojureScript. It's a pretty direct
rewrite from the Clojure version. Any bugs introduced in the port seem
to be insufficiently troublesome to prevent the following simple
sanity check from working:

(loop [m cljs.core.PersistentHashMap/EMPTY i 0]
(if (< i 10000)
(recur (assoc m i i) (inc i))
(loop [i 0]
(if (< i 10000)
(do (assert (== i (get m i)))
(recur (inc i)))))))

Then there's also the ./script/test suite -- it seems to work with
things rewired to use PersistentHashMap.

(NB. the "sanity check above", at least on Rhino, is noticeably faster
than the version with {} bound to m at the start.)

The impl is available in my fork on branch persistent-hash-map [1] and
in the first patch attached. This branch does *not* have any
"rewiring" included, so persistent hash maps only arise through direct
manipulation of cljs.core.PersistentHashMap. I also have a
persistent-hash-map-tests branch [2] where cljs.core/hash-map uses
PersistentHashMap and the compiler emits
cljs.core.PersistentHashMap/fromArrays for all calls to emit :map; as
mentioned above, ./script/test does not complain.

Note that I have done no testing at all for hash collisions (will do
soon); I wouldn't be surprised if there were some bugs left in and
around HashCollisionNode, but hopefully it won't be anything major.
There are clear next steps (use other map types for small objects as
appropriate etc.) which I'll get around to after ironing out the impl
here.

Looking forward to any comments, bug reports etc.

Sincerely,
Michał

[1] https://github.com/michalmarczyk/clojurescript/tree/persistent-hash-map
[2] https://github.com/michalmarczyk/clojurescript/tree/persistent-hash-map-tests

0001-PersistentHashMap-ported-from-Clojure.patch

David Nolen

unread,
Apr 11, 2012, 5:29:28 PM4/11/12
to cloju...@googlegroups.com
Excellent. Would be great if you went ahead and created a patch and ticket in JIRA. I'm sure there'll be feedback and you can evolve the patch there.

Thanks!

David


--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.


Michał Marczyk

unread,
Apr 11, 2012, 7:23:05 PM4/11/12
to cloju...@googlegroups.com
Done:

http://dev.clojure.org/jira/browse/CLJS-178

The ticket description includes a couple of silly timings (basically
(time ...) in Rhino around a loop like the one above) --
PersistentHashMap goes head to head with HashMap and wins with 1.1s
vs. 10.5s on 10000 iterations and 11.8s vs.
I'm-not-gonna-wait-any-more on 100000. :-)

Sincerely,
Michał

Reply all
Reply to author
Forward
0 new messages