Repository navigation
Simplify identifier creation in ConcatenatedModules - #6001
Merged
Merged
Conversation
Contributor
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
Member
|
I did measure it and calling hash.update often is more expensive than calling it with a large string. As explanation I would guess |
Member
|
But thanks for the PR. We can optimize webpack by doing the reverse: calling hash.update less often and instead concatenate string. |
sokra
requested changes
Nov 23, 2017
This was implemented in webpack#5997 to fix some memory issues, but I think we can make this a little more efficient. By using a single forEach instead of a map, filter, and join, we avoid unnecessary array creations and iterations.
lencioni
force-pushed
the
concatenation-efficiency
branch
from
November 23, 2017 16:01
f05724b to
5968f6e
Compare
Contributor
Contributor
Author
|
Thanks for doing the profiling @sokra! I've added a commit to this PR that incorporates this change. |
lencioni
force-pushed
the
concatenation-efficiency
branch
from
November 23, 2017 16:02
5968f6e to
7967700
Compare
egoroof
reviewed
Nov 23, 2017
| switch(info.type) { | ||
| case "concatenated": | ||
| return info.module.identifier(); | ||
| let orderedConcatenationListIdentifiers; |
There was a problem hiding this comment.
let a;
a += 'wat';
console.log(a); // "undefinedwat"
Contributor
Author
There was a problem hiding this comment.
lol, woops! fixed now. Thanks!
| for(let i = 0; i < this._orderedConcatenationList.length; i++) { | ||
| if(this._orderedConcatenationList[i].type === "concatenated") { | ||
| orderedConcatenationListIdentifiers += this._orderedConcatenationList[i].module.identifier(); | ||
| orderedConcatenationListIdentifiers += " "; |
@sokra did some profiling and it seems that calling crypto.update multiple times is slower than calling it once with a large string. > As explanation I would guess update calls into node.js C++ + OpenSSL > while concatenating strings is very optimized in JIT. To take better advantage of this information, I have rewritten this performance-sensitive code to build up a concatenated string and then hash it at the end. Since we are thinking about performance here, I opted for a regular for loop instead of using the forEach iterator. I also did some basic benchmarking of string concatenation strategies and discovered that separating out the addition of the extra space into its own concatenation line instead of tacking it on to the end of a single concatenation might just barely have the edge in terms of performance. I think it is also very readable this way, so it seems like a good tradeoff to make: a little lost conciseness for speed.
lencioni
force-pushed
the
concatenation-efficiency
branch
from
November 23, 2017 16:31
7967700 to
37d70bd
Compare
sokra
approved these changes
Nov 24, 2017
Member
|
Thanks |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What kind of change does this PR introduce?
Optimization
Did you add tests for your changes?
No
If relevant, link to documentation update:
Summary
This was implemented in #5997 to fix some memory issues, but I think we
can make this a little more efficient. By using a single forEach instead
of a map, filter, and join, we avoid unnecessary array creations and
iterations.
Does this PR introduce a breaking change?
No
Other information