2024 Clojure 状态调查!中分享你的想法。

欢迎!请查看关于页面以了解更多有关此运作方式的信息。

0 投票
ClojureScript

关键词函数可以加速。这在进行 XHR 时动态创建关键词时很重要。

该补丁现在与 Clojure 更加紧密匹配(使用子串)。它也针对传递字符串进行了优化。

结果

`
( enable-console-print! )
( let [sims 1000000]
( dotimes [ _ 2]

(doseq [x ["foo" "foo/bar" [nil "foo"] ["foo" "bar"] [:foo :bar] [nil :foo]]]
  (prn "Testing keyword with: " x)
  (if (vector? x)
    (do (simple-benchmark [[a0 a1] x] (set! js/FOOO (keyword a0 a1)) sims)
        (simple-benchmark [[a0 a1] x] (set! js/FOOO (keyword2 a0 a1)) sims))
    (do (simple-benchmark [] (set! js/FOOO (keyword x)) sims)
        (simple-benchmark [] (set! js/FOOO (keyword2 x)) sims))))))

"测试关键词为: " "foo"
[], (set! js/FOOO (keyword x)), 1000000 运行,194 毫秒
[], (set! js/FOOO (keyword2 x)), 1000000 运行,71 毫秒
"测试关键词为: " "foo/bar"
[], (set! js/FOOO (keyword x)), 1000000 运行,260 毫秒
[], (set! js/FOOO (keyword2 x)), 1000000 运行,104 毫秒
"测试关键词为: " [nil "foo"] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 运行,278 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 运行,188 毫秒
"测试关键词为: " ["foo" "bar"] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 运行,379 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 运行,215 毫秒
"测试关键词为: " [:foo :bar] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 运行,351 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 运行,207 毫秒
"测试关键词为: " [nil :foo] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 运行,376 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 运行,37 毫秒
`

4 答案

0 投票

评论人:aralo

更改了以下行为

((juxt namespace name) (keyword "foo/bar/hmm")) => [nil "foo"] (.-fqn (keyword "foo/bar/hmm")) => "foo/bar/hmm" ((juxt namespace name) (keyword2 "foo/bar/hmm")) => ["foo" "bar/hmm"] (.-fqn (keyword2 "foo/bar/hmm")) => "foo/bar/hmm"

Clojure 1.9

((juxt namespace name) (keyword "foo/bar/hmm")) => ["foo" "bar/hmm"]

所以:太好了

0 投票

评论人:mfikes

将 CLJS-2120.patch 添加到 Patch Tender (i)

0 投票

评论人:mfikes

CLJS-2120.patch 通过 CI 和 Canary 测试

0 投票
参考: https://clojure.atlassian.net/browse/CLJS-2120(由 aralo 报告)
...