Skip to content

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

Merged
existentialism merged 3 commits into
babel:masterfrom
JLHwung:object-spread2-performance-regression
Jul 11, 2019
Merged

perf: match ownKeys perf to the one of objectSpread#10189
existentialism merged 3 commits into
babel:masterfrom
JLHwung:object-spread2-performance-regression

Conversation

@JLHwung

@JLHwung JLHwung commented Jul 9, 2019

Copy link
Copy Markdown
Contributor
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.

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch!

@babel-bot

babel-bot commented Jul 9, 2019

Copy link
Copy Markdown
Collaborator

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

@existentialism existentialism left a comment

Copy link
Copy Markdown
Member

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

nicolo-ribaudo commented Jul 9, 2019

Copy link
Copy Markdown
Member

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

JLHwung commented Jul 9, 2019

Copy link
Copy Markdown
Contributor Author

(especially the comment!)

The idea comes from discussion with @nicolo-ribaudo

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