Commit 67fb765
fs: improve promise based readFile performance for big files
This significantly reduces the peak memory for the promise
based readFile operation by reusing a single memory chunk after
each read and strinigifying that chunk immediately.
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #44295
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>1 parent 9c7e664 commit 67fb765Copy full SHA for 67fb765
File tree
Expand file treeCollapse file tree
4 files changed
+82
-37
lines changedOpen diff view settings
Filter options
- benchmark/fs
- lib
- internal/fs
- test/parallel
Expand file treeCollapse file tree
4 files changed
+82
-37
lines changedOpen diff view settings
Collapse file
benchmark/fs/readfile-promises.js
Copy file name to clipboardExpand all lines: benchmark/fs/readfile-promises.js+8-1Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | | - |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
20 | 27 | |
21 | 28 | |
22 | 29 | |
|
Collapse file
+5Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
339 | 339 | |
340 | 340 | |
341 | 341 | |
| 342 | + |
| 343 | + |
| 344 | + |
342 | 345 | |
343 | 346 | |
344 | 347 | |
| ||
348 | 351 | |
349 | 352 | |
350 | 353 | |
| 354 | + |
| 355 | + |
351 | 356 | |
352 | 357 | |
353 | 358 | |
|
Collapse file
lib/internal/fs/promises.js
Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js+54-33Lines changed: 54 additions & 33 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
86 | 86 | |
87 | 87 | |
88 | 88 | |
| 89 | + |
89 | 90 | |
90 | 91 | |
91 | 92 | |
| ||
416 | 417 | |
417 | 418 | |
418 | 419 | |
| 420 | + |
| 421 | + |
419 | 422 | |
420 | 423 | |
421 | 424 | |
422 | 425 | |
423 | 426 | |
424 | 427 | |
425 | 428 | |
426 | | - |
| 429 | + |
| 430 | + |
427 | 431 | |
428 | 432 | |
429 | | - |
430 | | - |
| 433 | + |
| 434 | + |
| 435 | + |
| 436 | + |
431 | 437 | |
432 | 438 | |
433 | 439 | |
434 | 440 | |
435 | 441 | |
436 | | - |
437 | 442 | |
438 | | - |
439 | | - |
440 | | - |
441 | | - |
| 443 | + |
| 444 | + |
| 445 | + |
| 446 | + |
| 447 | + |
| 448 | + |
| 449 | + |
442 | 450 | |
443 | | - |
444 | | - |
445 | | - |
446 | | - |
447 | | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
| 451 | + |
| 452 | + |
453 | 453 | |
454 | 454 | |
455 | 455 | |
456 | 456 | |
457 | | - |
| 457 | + |
458 | 458 | |
459 | | - |
460 | | - |
461 | | - |
462 | | - |
463 | | - |
| 459 | + |
| 460 | + |
| 461 | + |
| 462 | + |
| 463 | + |
| 464 | + |
| 465 | + |
| 466 | + |
| 467 | + |
| 468 | + |
| 469 | + |
| 470 | + |
| 471 | + |
| 472 | + |
| 473 | + |
| 474 | + |
| 475 | + |
| 476 | + |
| 477 | + |
| 478 | + |
| 479 | + |
| 480 | + |
| 481 | + |
| 482 | + |
| 483 | + |
464 | 484 | |
465 | | - |
466 | 485 | |
467 | | - |
468 | | - |
469 | | - |
470 | | - |
471 | | - |
472 | | - |
| 486 | + |
| 487 | + |
| 488 | + |
| 489 | + |
| 490 | + |
| 491 | + |
| 492 | + |
| 493 | + |
| 494 | + |
| 495 | + |
473 | 496 | |
474 | | - |
475 | | - |
476 | 497 | |
477 | 498 | |
478 | 499 | |
|
Collapse file
test/parallel/test-fs-promises-readfile.js
Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises-readfile.js+15-3Lines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
1 | 2 | |
2 | 3 | |
3 | 4 | |
| ||
6 | 7 | |
7 | 8 | |
8 | 9 | |
| 10 | + |
| 11 | + |
9 | 12 | |
10 | 13 | |
11 | 14 | |
12 | 15 | |
13 | 16 | |
14 | 17 | |
15 | | - |
16 | | - |
17 | | - |
| 18 | + |
18 | 19 | |
19 | 20 | |
20 | 21 | |
| ||
69 | 70 | |
70 | 71 | |
71 | 72 | |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
72 | 83 | |
73 | 84 | |
74 | 85 | |
75 | 86 | |
76 | 87 | |
77 | 88 | |
78 | 89 | |
| 90 | + |
79 | 91 | |
0 commit comments