<< Back to previous view

[CLJS-326] hash-set and PersistentHashSet/fromArray == faster set construction Created: 24/Jun/12  Updated: 27/Jul/13  Resolved: 25/Jun/12

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Brandon Bloom Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: patch, patch,

Attachments: Text File making-sets.patch     Text File making-sets-squashed.patch    
Patch: Code and Test

 Description   

As discussed with mmarczyk in irc, the attached patch implements Clojure's hash-set function and modifies the compiler to create sets using a new fromArray static method. To test these, I created three new benchmarks. Here's before and after benchmark results:

$ time ./script/benchmark | grep '#{'
[], #{}, 100000 runs, 77 msecs
[], #{1 2 3}, 100000 runs, 582 msecs
[coll #{1 2 3}], (conj coll 4), 100000 runs, 104 msecs
[], #{}, 100000 runs, 740 msecs
[], #{1 2 3}, 100000 runs, 1809 msecs
[coll #{1 2 3}], (conj coll 4), 100000 runs, 221 msecs
[], #{}, 100000 runs, 281 msecs
[], #{1 2 3}, 100000 runs, 1310 msecs
[coll #{1 2 3}], (conj coll 4), 100000 runs, 288 msecs
./script/benchmark 109.41s user 3.82s system 127% cpu 1:28.96 total

$ time ./script/benchmark | grep '#{'
[], #{}, 100000 runs, 1 msecs
[], #{1 2 3}, 100000 runs, 333 msecs
[coll #{1 2 3}], (conj coll 4), 100000 runs, 100 msecs
[], #{}, 100000 runs, 1 msecs
[], #{1 2 3}, 100000 runs, 1670 msecs
[coll #{1 2 3}], (conj coll 4), 100000 runs, 325 msecs
[], #{}, 100000 runs, 1 msecs
[], #{1 2 3}, 100000 runs, 689 msecs
[coll #{1 2 3}], (conj coll 4), 100000 runs, 321 msecs
./script/benchmark 103.94s user 4.89s system 108% cpu 1:39.88 total
grep '#{' 0.00s user 0.00s system 0% cpu 1:39.85 total



 Comments   
Comment by Brandon Bloom [ 24/Jun/12 8:47 PM ]

Slightly better patch with the EMPTY case

Comment by David Nolen [ 24/Jun/12 10:13 PM ]

Getting a weird error when I try to run the tests. Also can we squash the commits? Thanks!

Comment by Brandon Bloom [ 24/Jun/12 10:24 PM ]

Squashed patch.

Comment by Brandon Bloom [ 24/Jun/12 10:28 PM ]

Squashed and rebased on latest master. Is the rule no-multi-commit patches? Or simply just not for such small patches? In this case, I made and tested each each change in sequence. I also wanted the benchmarks to have a different sha1, so that the perf improvement would show up in the graphs. I'll try to provide squashed patches in the future.

What weird error are you getting? Works for me :-P

Comment by Brandon Bloom [ 24/Jun/12 10:33 PM ]

Updating 2nd benchmark in description to include the EMPTY optimization

Comment by David Nolen [ 25/Jun/12 6:33 AM ]

fixed, http://github.com/clojure/clojurescript/commit/c60df78e2fd318109a9338a87277c11565b506ae

Generated at Sat Dec 20 17:50:52 CST 2014 using JIRA 4.4#649-r158309.