Commit 78c2262
crypto: implement crypto.hash()
This patch introduces a helper crypto.hash() that computes
a digest from the input at one shot. This can be 1.2-1.6x faster
than the object-based createHash() for smaller inputs (<= 5MB)
that are readily available (not streamed) and incur less memory
overhead since no intermediate objects will be created.
PR-URL: #51044
Refs: nodejs/performance#136
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>1 parent 5a2d2da commit 78c2262Copy full SHA for 78c2262
File tree
Expand file treeCollapse file tree
9 files changed
+272
-8
lines changedOpen diff view settings
Filter options
- benchmark/crypto
- doc/api
- lib
- internal/crypto
- src
- api
- crypto
- test/parallel
Expand file treeCollapse file tree
9 files changed
+272
-8
lines changedOpen diff view settings
Collapse file
benchmark/crypto/oneshot-hash.js
Copy file name to clipboard+42Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
Collapse file
+61Lines changed: 61 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3630 | 3630 | |
3631 | 3631 | |
3632 | 3632 | |
| 3633 | + |
| 3634 | + |
| 3635 | + |
| 3636 | + |
| 3637 | + |
| 3638 | + |
| 3639 | + |
| 3640 | + |
| 3641 | + |
| 3642 | + |
| 3643 | + |
| 3644 | + |
| 3645 | + |
| 3646 | + |
| 3647 | + |
| 3648 | + |
| 3649 | + |
| 3650 | + |
| 3651 | + |
| 3652 | + |
| 3653 | + |
| 3654 | + |
| 3655 | + |
| 3656 | + |
| 3657 | + |
| 3658 | + |
| 3659 | + |
| 3660 | + |
| 3661 | + |
| 3662 | + |
| 3663 | + |
| 3664 | + |
| 3665 | + |
| 3666 | + |
| 3667 | + |
| 3668 | + |
| 3669 | + |
| 3670 | + |
| 3671 | + |
| 3672 | + |
| 3673 | + |
| 3674 | + |
| 3675 | + |
| 3676 | + |
| 3677 | + |
| 3678 | + |
| 3679 | + |
| 3680 | + |
| 3681 | + |
| 3682 | + |
| 3683 | + |
| 3684 | + |
| 3685 | + |
| 3686 | + |
| 3687 | + |
| 3688 | + |
| 3689 | + |
| 3690 | + |
| 3691 | + |
| 3692 | + |
| 3693 | + |
3633 | 3694 | |
3634 | 3695 | |
3635 | 3696 | |
|
Collapse file
+2Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
107 | 107 | |
108 | 108 | |
109 | 109 | |
| 110 | + |
110 | 111 | |
111 | 112 | |
112 | 113 | |
| ||
227 | 228 | |
228 | 229 | |
229 | 230 | |
| 231 | + |
230 | 232 | |
231 | 233 | |
232 | 234 | |
|
Collapse file
lib/internal/crypto/hash.js
Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js+31Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3 | 3 | |
4 | 4 | |
5 | 5 | |
| 6 | + |
6 | 7 | |
7 | 8 | |
8 | 9 | |
| ||
11 | 12 | |
12 | 13 | |
13 | 14 | |
| 15 | + |
14 | 16 | |
15 | 17 | |
16 | 18 | |
| ||
29 | 31 | |
30 | 32 | |
31 | 33 | |
| 34 | + |
| 35 | + |
32 | 36 | |
33 | 37 | |
34 | 38 | |
| ||
40 | 44 | |
41 | 45 | |
42 | 46 | |
| 47 | + |
43 | 48 | |
44 | 49 | |
45 | 50 | |
46 | 51 | |
47 | 52 | |
48 | 53 | |
49 | 54 | |
| 55 | + |
50 | 56 | |
51 | 57 | |
52 | 58 | |
| ||
188 | 194 | |
189 | 195 | |
190 | 196 | |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
191 | 221 | |
192 | 222 | |
193 | 223 | |
194 | 224 | |
| 225 | + |
195 | 226 | |
Collapse file
+10Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
109 | 109 | |
110 | 110 | |
111 | 111 | |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
112 | 122 | |
113 | 123 | |
114 | 124 | |
|
Collapse file
+78-8Lines changed: 78 additions & 8 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
202 | 202 | |
203 | 203 | |
204 | 204 | |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | + |
| 268 | + |
| 269 | + |
205 | 270 | |
206 | 271 | |
207 | 272 | |
| ||
216 | 281 | |
217 | 282 | |
218 | 283 | |
| 284 | + |
219 | 285 | |
220 | 286 | |
221 | 287 | |
| ||
229 | 295 | |
230 | 296 | |
231 | 297 | |
| 298 | + |
232 | 299 | |
233 | 300 | |
234 | 301 | |
| ||
294 | 361 | |
295 | 362 | |
296 | 363 | |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
| 364 | + |
| 365 | + |
| 366 | + |
| 367 | + |
| 368 | + |
| 369 | + |
| 370 | + |
| 371 | + |
| 372 | + |
| 373 | + |
| 374 | + |
305 | 375 | |
306 | 376 | |
307 | 377 | |
|
Collapse file
+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
26 | 26 | |
27 | 27 | |
28 | 28 | |
| 29 | + |
29 | 30 | |
30 | 31 | |
31 | 32 | |
|
Collapse file
+4Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
446 | 446 | |
447 | 447 | |
448 | 448 | |
| 449 | + |
| 450 | + |
| 451 | + |
| 452 | + |
449 | 453 | |
450 | 454 | |
451 | 455 | |
|
Collapse file
test/parallel/test-crypto-oneshot-hash.js
Copy file name to clipboard+43Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
0 commit comments