在你的想法中分享关于 2024 年 Clojure 调查结果!

欢迎!请参阅 关于 页面了解更多有关该网站的工作方式。

+1
ClojureScript
使用 {{select-keys}} 时,使用 {{not=}} 来比较关键字。相反,使用 {{keyword-identical?}} 可以带来一定的速度提升(基准和引擎的平均提升为1.34)。注意,使用 {{identical?}} 和 {{lookup-sentinel}} 似乎不会提高性能。

加速摘要


            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



之前

使用 V8 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 179 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 121 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 183 msecs

使用 SpiderMonkey 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 251 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 201 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 290 msecs

使用 JavaScriptCore 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 112 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 73 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 119 msecs

使用 Nashorn 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 1277 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 524 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 635 msecs

使用 ChakraCore 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 463 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 268 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 414 msecs


之后


使用 V8 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 155 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 112 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 169 msecs

使用 SpiderMonkey 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 146 msecs
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,135 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,173 毫秒

使用 JavaScriptCore 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,84 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,54 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,95 毫秒

使用 Nashorn 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,1099 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,502 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,648 毫秒

使用 ChakraCore 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,292 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,151 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,240 毫秒

9 个答案

0

评论者:slipset

只想将您的注意力引向CLJ-1789,在其中用reduce函数重新实现select-keys带来显著的速度提升。
添加了一个补丁以展示这种方法。

0

评论者:mfikes

Erik的补丁的性能数字

`

        V8: 0.81, 1.14, 1.30

SpiderMonkey: 1.49, 1.31, 1.58
JavaScriptCore: 1.02, 0.99, 0.96

   Nashorn: 1.13, 1.17, 1.21
ChakraCore: 1.27, 1.35, 1.28

`

之后

`
使用 V8 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,220 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,106 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,141 毫秒

使用 SpiderMonkey 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,169 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,153 毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 183 msecs

使用 JavaScriptCore 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,110 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,74 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,124 毫秒

使用 Nashorn 进行基准测试
;;; select-keys
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c]),200000 次运行,1128 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :x]),200000 次运行,447 毫秒
[:a 1, :b 2, :c 3, :d 4],(select-keys m [:a :b :c :x :y :z]),200000 次运行,524 毫秒

使用 ChakraCore 进行基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,366毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,199毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,323毫秒
`

0

评论者:slipset

上传了一个不带transients的补丁。

0

评论者:mfikes

由于CLJ-1789补丁在大映射中表现更好,这里使用该票务中的数据对此进行了额外的性能测试,测试了我之前附件中的原始补丁以及Erik后续的补丁。您可以看出,CLJ-1789方法对ClojureScript也很有帮助。

Erik,我看到您附加了一个第三个补丁。我建议在每个此类补丁中添加性能数字,以便可以更轻松地评估补丁在高级优化下的效果。

`
关键词-identical? 引擎 CLJ-1789

        V8:               1.13      1.29

SpiderMonkey:1.89 2.39
JavaScriptCore:1.02 0.96

   Nashorn:               1.12      1.42
ChakraCore:               1.68      1.82

`

之前

`
使用 V8 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,373毫秒

使用 SpiderMonkey 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,668毫秒

使用 JavaScriptCore 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,200毫秒

使用 Nashorn 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,2236毫秒

使用 ChakraCore 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,1074毫秒
`

执行(keyword-identical?)后

`
使用 V8 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,330毫秒

使用 SpiderMonkey 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,353毫秒

使用 JavaScriptCore 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,197毫秒

使用 Nashorn 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,1991毫秒

使用 ChakraCore 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,640毫秒
`

执行(CLJ-1789)后

`
使用 V8 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,290毫秒

使用 SpiderMonkey 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,279毫秒

使用 JavaScriptCore 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]), 200000次运行,209毫秒

使用 Nashorn 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}],(select-keys m [:a :c :b :d :e :f :g]),200000次运行,1578毫秒

使用 ChakraCore 进行基准测试
;;; select-keys
[m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}],(select-keys m [:a :c :b :d :e :f :g]),200000次运行,591毫秒
`

0

评论者:slipset

这两个补丁现在都应该有基准测试了

0

评论者:slipset

哦,至于更大的映射的注释,我认为性能transient位依赖于所选键的大小,
例如,在映射中找到的键越多,我们从conj!获得的收益就越大

0

评论者:mfikes

运行这些4个基准测试

[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]),200000次运行 [m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]),200000次运行 [m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]),200000次运行 [m {:a "b", :c "d", :b "b", :d "d", :e "e", :f "f", :g "g"}], (select-keys m [:a :c :b :d :e :f :g]),200000次运行

在所有5个引擎上运行这三个附加补丁后,在我的机器上得到以下加速效果

`
CLJS-2383.patch

        V8: 1.11, 1.10, 1.64, 1.18  Avg: 1.26

SpiderMonkey:2.36,1.46,1.79,2.02 平均:1.91
JavaScriptCore:1.28,1.34,1.23,1.49 平均:1.34

   Nashorn: 1.19, 1.17, 1.06, 1.29  Avg: 1.18
ChakraCore: 1.61, 1.78, 1.75, 2.11  Avg: 1.81
                            Overall avg: 1.50
     Avg excluding Nashorn & ChakraCore: 1.50

0001-CLJS-2383-Speed-up-select-keys.patch

        V8: 0.70, 0.95, 1.05, 1.23  Avg: 0.98

SpiderMonkey:1.20,1.09,1.05,2.03 平均:1.34
JavaScriptCore:0.78,0.84,0.83,1.02 平均:0.87

   Nashorn: 1.18, 1.08, 1.02, 1.48  Avg: 1.19
ChakraCore: 1.00, 1.12, 1.19, 1.75  Avg: 1.27
                            Overall avg: 1.13
     Avg excluding Nashorn & ChakraCore: 1.06	

0002-CLJS-2383-Speed-up-select-keys-no-transient.patch

        V8: 1.28, 1.45, 1.37, 1.33  Avg: 1.36

SpiderMonkey:1.54,1.44,1.70,2.17 平均:1.71
JavaScriptCore:1.01,0.99,1.03,1.13 平均:1.04

   Nashorn: 1.39, 1.21, 1.14, 1.26  Avg: 1.25
ChakraCore: 1.20, 1.23, 1.19, 1.39  Avg: 1.25
                            Overall avg: 1.32
     Avg excluding Nashorn & ChakraCore: 1.37	

`

0

评论者:mfikes

总结:如果应用,CLJS-2383.patch将是应用的最佳选择,因为它提供了所有补丁中最大的加速效果。

0
参考:[a href="https://clojure.atlassian.net/browse/CLJS-2383" rel="nofollow" target="_blank">https://clojure.atlassian.net/browse/CLJS-2383
...