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次运行,179毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,121毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,183毫秒

SpiderMonkey基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,251毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,201毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,290毫秒

JavaScriptCore基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,112毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,73毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,119毫秒

Nashorn基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,1277毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,524毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,635毫秒

ChakraCore基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,463毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,268毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,414毫秒


之后


V8基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,155毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,112毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,169毫秒

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

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

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

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

9 答案

0 点赞
by

由:slipset 发表的评论

只想引起您的注意,CLJ-1789中,将select-keys以其实现方式重写,显著提高了速度。
添加了一个补丁来展示这种方法。

0 点赞
by

由: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
[[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,220毫秒
[[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,106毫秒
[[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,141毫秒

SpiderMonkey基准测试
;;; select-keys
[[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,169毫秒
[[m {: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次运行,183毫秒

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

Nashorn基准测试
;;; select-keys
[[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,1128毫秒
[[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,447毫秒
[m {: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 发表的评论

同时上传了一个无持久状态的补丁。

0 点赞

由:mfikes 发表的评论

由于CLJ-1789补丁对较大的映射效果更好,因此这里有一个额外的性能测试,该测试使用该票的数据,测试了我附加的原补丁以及Erik随后的补丁。您可以看到CLJ-1789方法也对ClojureScript具有回报。

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

`
引擎keyword-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!中获得的好处就越多。
例如,找到的选键越多,从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 个引擎和 3 个附加补丁可以获得以下加速

`
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 点赞
回答者
参考:[https://clojure.atlassian.net/browse/CLJS-2383](https://clojure.atlassian.net/browse/CLJS-2383)(由mfikes报告)
...