Closed NeilFraser closed 1 year ago
If allowing ES6, why not use a
Map
instead of aSet
, to make object number lookup faster inencodeValue_
?
That's a really good idea. I implemented it just now, and found zero performance improvement in either Chrome or Firefox. The data was very noisy due to the non-deterministic nature of the JIT, but I saw hints that it might actually be very slightly slower. My only guess is that the overhead of a Map vs a Set exactly offsets the gain of using Map.get vs Array.indexOf.
Never mind, it's only a wash if one has a minimal number of objects (~4000). Larger environments (> 10,000) do show a significant speed-up. Changed. https://github.com/NeilFraser/JS-Interpreter/commit/2835162fb5b10bc124ef040a2914d9f7ef9eeba2
I note that I made this change in Code City back in 2018 in google/CodeCity#242; regrettably I did not at the time record whether it made a measurable difference to serialisation.
If allowing ES6, why not use a
Map
instead of aSet
, to make object number lookup faster inencodeValue_
?