Chrome poor performance when calling array.unshift on a large array. #1211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm really enjoying preact, thanks for developing the project!
I noticed when quickly adding and removing a large amount of nodes, Chrome 68 experiences poor performance. Using the profiler, most of the time is spent in
mounts.unshift()
. This PR changesmounts.unshift()
tomounts.push()
and reversing the order that mounts are flushed to maintain functionality.This project demonstrates the issue: https://github.com/lowaa/preact-perf
With preact 8.3.1, Chrome 68 running on a macbook pro 2018:
After the change:
The scripting time is significantly decreased but maximum heap usage goes up by ~25%
Also tested on Firefox 62 and Edge 17. These browsers did not seem to have an issue with the use of
array.unshift()
. The change toarray.push
also seemed to have no effect.