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

perf: match ownKeys perf to the one of objectSpread #10189

Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jul 9, 2019

Q                       A
Fixed Issues? Fixes a performance regression introduced in #10171, Fixes #10192
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR addresses a performance regression introduced at #10171.

Object.keys returns a list of enumerable property names. Hence we filter enumerable only on the property symbols. Note that this approach is also practiced in helpers.objectSpread.

In practice the most frequent use cases of objectSpread is merging two plain objects, which means we can skip a sweep of already enumerable property names. I also drafted a jsPerf snippet on the performance difference. It is 10% faster on V8 75 when merging two object with 512 keys.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@babel-bot
Copy link
Collaborator

babel-bot commented Jul 9, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11092/

@JLHwung JLHwung force-pushed the object-spread2-performance-regression branch from d5f8af0 to 49f8d4c Compare July 9, 2019 21:24
Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (especially the comment!)

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 9, 2019

Thanks!

(As a side note, I really like having more ✔️ than usual!)

EDIT: I was going to merge this PR, I'll wait for CI to finish.

@JLHwung
Copy link
Contributor Author

JLHwung commented Jul 9, 2019

(especially the comment!)

The idea comes from discussion with @nicolo-ribaudo

@JLHwung JLHwung mentioned this pull request Jul 10, 2019
@existentialism existentialism merged commit 5d9a786 into babel:master Jul 11, 2019
@JLHwung JLHwung deleted the object-spread2-performance-regression branch July 15, 2019 19:57
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 14, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: helpers area: perf outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories Spec: Object Rest/Spread
Projects
None yet
Development

Successfully merging this pull request may close these issues.

objectSpread2 failure
5 participants