Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid calling hash.update multiple times in ConcatenatedModules
@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.
- Loading branch information