We're updating the issue view to help you get more done. 

Collection hashers should use iterators

Description

In CLJS hash-ordered-coll and hash-unordered-coll currently consume their collections using seq instead of an iterator. Most core collection types have an efficient -iterator implementation which avoids the extra allocations inherent in seq.

Using iterators instead shows a modest performance improvement with larger collections and more frequent iterations; benchmark-runner size (1000) and repetition count (100) shows no perceptible difference on my machine (Ubuntu 18.04 using "Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz")

cljs.benchmark-runner

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (ns cljs.benchmark-runner (:refer-clojure :exclude [println])) (def println print) (set! *print-fn* js/print) ;; Note that coll size and repetition count are both ;; 10x what benchmark-runner usually uses. (def hash-coll-test (loop [i 0 r []] (if (< i 10000) (recur (inc i) (conj r (str "foo" i))) r))) (def hash-imap-test (loop [i 0 r {}] (if (< i 10000) (recur (inc i) (conj r [(keyword (str "foo" i)) i])) r))) (def hash-imap-int-test (loop [i 0 r {}] (if (< i 10000) (recur (inc i) (conj r [i i])) r)))
1 2 3 4 5 6 7 8 9 10 11 12 ## benchmark run on Ubuntu 18.04 using "Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz" ## benchmark results for master Benchmarking with V8 [coll hash-coll-test], (hash-ordered-coll coll), 1000 runs, 1831 msecs [coll hash-imap-test], (hash-unordered-coll coll), 1000 runs, 6506 msecs [coll hash-imap-int-test], (hash-unordered-coll coll), 1000 runs, 8439 msecs ## benchmark results with this patch Benchmarking with V8 [coll hash-coll-test], (hash-ordered-coll coll), 1000 runs, 1629 msecs [coll hash-imap-test], (hash-unordered-coll coll), 1000 runs, 5753 msecs [coll hash-imap-int-test], (hash-unordered-coll coll), 1000 runs, 6810 msecs

Environment

None

Status

Assignee

David Nolen

Reporter

Francis Avila

Labels

Approval

None

Patch

Code

Priority

Minor