Details

Type: Enhancement

Status: Open

Priority: Minor

Resolution: Unresolved

Affects Version/s: 1.9.908

Fix Version/s: None

Component/s: None

Labels:

Patch:Code and Test
Description
selectkeys uses not= to compare keywords. Instead, using keywordidentical? results in decent speedups (an average of 1.34 across benchmarks and engines). Note that using identical? and lookupsentinel doesn't appear to improve perf.
Speedup Summary:
V8: 1.15, 1.08, 1.08 SpiderMonkey: 1.71, 1.48, 1.67 JavaScriptCore: 1.33, 1.35, 1.25 Nashorn: 1.16, 1.04, 0.97 ChakraCore: 1.59, 1.66, 1.72
Before:
Benchmarking with V8 ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 179 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 121 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 183 msecs Benchmarking with SpiderMonkey ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 251 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 201 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 290 msecs Benchmarking with JavaScriptCore ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 112 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 73 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 119 msecs Benchmarking with Nashorn ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 1277 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 524 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 635 msecs Benchmarking with ChakraCore ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 463 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 268 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 414 msecs
After
Benchmarking with V8 ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 155 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 112 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 169 msecs Benchmarking with SpiderMonkey ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 146 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 135 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 173 msecs Benchmarking with JavaScriptCore ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 84 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 54 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 95 msecs Benchmarking with Nashorn ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 1099 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 502 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 648 msecs Benchmarking with ChakraCore ;;; selectkeys [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c]), 200000 runs, 292 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :x]), 200000 runs, 151 msecs [m {:a 1, :b 2, :c 3, :d 4}], (selectkeys m [:a :b :c :x :y :z]), 200000 runs, 240 msecs
Just want to bring your attention to CLJ1789, where reimplementing `selectkeys` in terms of reduce gave a significant speedup.
Added a patch to show that way.