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](https://clojure.atlassian.net/browse/CLJS-2120)(由 aralo 报告)
...