Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome poor performance when calling array.unshift on a large array. #1211

Merged
merged 1 commit into from Sep 24, 2018

Conversation

lowaa
Copy link
Contributor

@lowaa lowaa commented Sep 13, 2018

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 changes mounts.unshift() to mounts.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:

image

After the change:

image

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 to array.push also seemed to have no effect.

…xperiences poor performance. Most of the time is spent in mounts.unshift(). Removing mounts.unshift and reversing the order that mounts are flushed.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 9b81167 on lowaa:remove-mounts-unshift into b5c4a36 on developit:master.

@marvinhagemeister
Copy link
Member

@lowaa Woa, that's dope 👍 👍 I love the detailed description of this PR and can confirm that this is noticeably faster due to not having to resize the array all the time 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants