Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

keyword function can be sped up. This matters when keywords are created dynamically when doing XHR.

The patch now matches Clojure more closely (using substring). It's also optimized for passing strings.

Results:

`
(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))))))

"Testing keyword with: " "foo"
[], (set! js/FOOO (keyword x)), 1000000 runs, 194 msecs
[], (set! js/FOOO (keyword2 x)), 1000000 runs, 71 msecs
"Testing keyword with: " "foo/bar"
[], (set! js/FOOO (keyword x)), 1000000 runs, 260 msecs
[], (set! js/FOOO (keyword2 x)), 1000000 runs, 104 msecs
"Testing keyword with: " [nil "foo"] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 runs, 278 msecs
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 runs, 188 msecs
"Testing keyword with: " ["foo" "bar"] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 runs, 379 msecs
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 runs, 215 msecs
"Testing keyword with: " [:foo :bar] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 runs, 351 msecs
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 runs, 207 msecs
"Testing keyword with: " [nil :foo] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 runs, 376 msecs
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 runs, 37 msecs
`

4 Answers

0 votes
by

Comment made by: aralo

Changes the behavior of:

((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"]

So: yay

0 votes
by

Comment made by: mfikes

CLJS-2120.patch added to Patch Tender (i)

0 votes
by

Comment made by: mfikes

CLJS-2120.patch passes CI and Canary (/)

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2120 (reported by aralo)
...