react icon indicating copy to clipboard operation
react copied to clipboard

memoization of step heaps, effectively preallocating weak arrays

Open nilsbecker opened this issue 11 years ago • 2 comments

this is another performance improvement suggestion. it's entirely possible that this breaks the JS backend. i have not tried.

weak array creations are reduced further by keeping old weak array heaps from previous steps around in a primitive stack. in my benchmarks where steps are fired in a tight loop, the commit cee407f decreased the runtime of a simulation between 20 and 40%. similar improvements are also seen in the minibenchmark https://gist.github.com/nilsbecker/2ec8d0a136e2fcc20184#file-react_minibenchmark-ml . compared to react 1.2.0, in my specific use cases, this in some cases gives a speedup of around 2 times.

nilsbecker avatar Jan 25 '15 20:01 nilsbecker

might be considered evil

It's not evil but it invalidates the thread safety properties mentioned in the documentation... Interesting though.

dbuenzli avatar Jan 26 '15 08:01 dbuenzli

i see. i guess to make something like this thread safe it would be better to work with immutable values? not sure how this would be done, or whether it can be done efficiently. about speed: i noticed that the speedup factor is larger when the call graph is small. it seems that a constant, relatively small overhead per step creation is removed, and this is most noticeable for small call graphs.

nilsbecker avatar Jan 26 '15 10:01 nilsbecker