ClojureScript

Have js-keys delegate directly to good.object/getKeys

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: 1.9.908
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code
  • Approval:
    Accepted

Description

js-keys is implemented using goog.object/forEach. This essentially results in JavaScript that does a for over each key in the object, (just like goog.object/getKeys), but instead of directly accumulating the keys in a JavaScript array, using forEach ends up incurring unnecessary overhead extracting (and ultimately discarding) the value associated with each key, and making a callback for each key. In :none mode, you can see that goog.object/getKeys can be twice as fast as js-keys at times (at least in JavaScriptCore—work for this ticket should probably include a new benchmark.)

This ticket asks that js-keys be implemented by directly delegating to good.object/getKeys. There are a few places, in printing, and in js->clj that could benefit from this speedup (and with the simple delegation, good.object/getKeys could even be inlined by hand at call sites if it improved perf).

Activity

Hide
Mike Fikes added a comment -
Speedup summary:

            V8:  7.2,  8.7
  SpiderMonkey: 29.5, 29.2
JavaScriptCore:  7.8,  4.8
       Nashorn:  6.2,  5.5
    ChakraCore:  3.6,  5.8


Before:

Benchmarking with V8
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 72 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 96 msecs

Benchmarking with SpiderMonkey
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 177 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 146 msecs

Benchmarking with JavaScriptCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 133 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 78 msecs

Benchmarking with Nashorn
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 804 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 749 msecs

Benchmarking with ChakraCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 91 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 129 msecs


After:

Benchmarking with V8
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 10 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 11 msecs

Benchmarking with SpiderMonkey
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 6 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 5 msecs

Benchmarking with JavaScriptCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 17 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 16 msecs

Benchmarking with Nashorn
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 128 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 136 msecs

Benchmarking with ChakraCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 25 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 22 msecs
Show
Mike Fikes added a comment -
Speedup summary:

            V8:  7.2,  8.7
  SpiderMonkey: 29.5, 29.2
JavaScriptCore:  7.8,  4.8
       Nashorn:  6.2,  5.5
    ChakraCore:  3.6,  5.8


Before:

Benchmarking with V8
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 72 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 96 msecs

Benchmarking with SpiderMonkey
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 177 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 146 msecs

Benchmarking with JavaScriptCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 133 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 78 msecs

Benchmarking with Nashorn
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 804 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 749 msecs

Benchmarking with ChakraCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 91 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 129 msecs


After:

Benchmarking with V8
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 10 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 11 msecs

Benchmarking with SpiderMonkey
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 6 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 5 msecs

Benchmarking with JavaScriptCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 17 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 16 msecs

Benchmarking with Nashorn
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 128 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 136 msecs

Benchmarking with ChakraCore
[obj (js-obj "a" 1 "b" 2) f js-keys], (f obj), 400000 runs, 25 msecs
[obj (js-obj "a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6) f js-keys], (f obj), 400000 runs, 22 msecs

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: