Commit 37d70bd
committed
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.1 parent 8fdf411 commit 37d70bd
1 file changed
+8
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
302 | 303 | | |
303 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
304 | 307 | | |
305 | 308 | | |
306 | 309 | | |
| |||
0 commit comments