-
Notifications
You must be signed in to change notification settings - Fork 65
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: remove object spreading #423
perf: remove object spreading #423
Conversation
be85caf
to
58f3f91
Compare
.gitignore
Outdated
@@ -3,3 +3,4 @@ npm-debug.log | |||
es | |||
lib | |||
node_modules | |||
.clinic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd rather not have non-package-related exclusions checked into source control. Directories and files can be ignored locally (and not checked into source control) by moving this line to .git/info/exclude
. This command will do it for you: echo .clinic >> .git/info/exclude
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger. Fixed!
Thanks again @baldurh! LGTM once that |
58f3f91
to
e469268
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Food for thought here - in Chrome 76+, spread is actually faster than Object.assign 🤷♀️ |
Wow that’s super interesting. We definitely have to take that into account. I ran the benchmarks on node 12 and |
Pulling in @jayeb to answer this from imgix's perspective. From my perspective, it's a tough call as there's no clear answer. I think we should accept this change as it is such a significant improvement, but aim to remove this in about a year's time (this could be put in a comment). |
I may be off-base here, but it seems to me that the performance of the spread operator in Chrome is mostly irrelevant--if this code is running in a browser, it's almost certainly going to be the Babel-compiled version, right? And since the compiled version isn't using the spread operator directly, it's kind of a moot point. This PR looks like an obvious win to me, but maybe I'm missing something. |
@jayeb Yes you’re absolutely right. I realised this also this morning but hadn’t gotten around to mention it 😄 So babel transpiles the spread operator to a function looping over the props of the object being spread. So that’s going to be slow in any environment 🙈 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets a 👍 from me as well. Based on the conversation, it seems like Object.assign
is the way we want to go here. Unless anyone has objections to wait, I'll merge today.
Description
I replaced all instances of the object spread operator with
Object.assign
. The results are quite remarkable:Benchmarks in ms. 100,000 iterations
Flamegraph before
Flamegraph after