ClojureScript

PersistentHashMap implementation

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

0001-PersistentHashMap-ported-from-Clojure.patch contains a port of Clojure's PersistentHashMap.

0002-...-.patch rewires cljs.core/hash-map and cljs.compiler/emit's :map method to use cljs.core.PersistentHashMap. With that in place, the regular cljs test suite runs fine.

As a quick sanity check,

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

runs fine under Rhino. Timing this loop produces the expected results: it takes 1.1s on my machine as written above and 10.5s with cljs.core.HashMap/EMPTY bound to m. With 100000 iterations, PersistentHashMap takes 11.8s, whereas HashMap takes forever.

TODO:

  • iron out any remaining bugs, add in missing protocols (if any) etc.,
  • test HashCollisionNode and related code,
  • use other map types for small maps and switch at some threshold.

See https://groups.google.com/d/topic/clojure-dev/DMcV4QwApuY/discussion.

Activity

Michał Marczyk made changes -
Michał Marczyk made changes -
Michał Marczyk made changes -
Michał Marczyk made changes -
Michał Marczyk made changes -
Michał Marczyk made changes -
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: