Repository navigation
Commit c150225
authored
fix(cache): accept a managedPaths RegExp without a capture group, and speed up pack writes (#21843)
* perf(serialization): dispatch cache items on their type
`ObjectMiddleware`'s write loop is the hottest function webpack runs while
storing the persistent cache. It opened with `Buffer.isBuffer(item)` and only
reached numbers, booleans and `undefined` after four more failed comparisons —
and counted over a 1,500-module build, those three are 1,066,959 of the
1,649,896 items it sees (64.6%), against 46,549 buffers (2.8%).
Dispatch on `typeof` instead, so each item reaches its branch directly. The
object branch also keys its type lookup on the serializer registration rather
than on a `${request}/${name}` string, dropping another 254,319 string
allocations per build. The wire format is unchanged: one registration is one
`(request, name)` pair, so the same entries are emitted in the same order.
Self time of that function drops from 296-321 ms to 201-230 ms over a
1,897-module fixture (`--cpu-prof`, two runs each, interleaved), and the cache
store measured through `compiler.close()` from 1,179 ms to 1,056 ms (median of
6 interleaved runs). Emitted output is byte-identical.
* fix: accept a snapshot.managedPaths RegExp without a capture group
The schema documents a `snapshot.managedPaths` entry as "a RegExp matching a
managed directory", but `FileSystemInfo` read the managed directory out of
`match[1]`. A pattern written exactly as documented — with no capture group —
therefore reached `getManagedItem(undefined, path)` and failed the build with
`TypeError: Cannot read properties of undefined (reading 'length')` from inside
the snapshot layer, naming nothing the user wrote.
Fall back to the whole match, which is the directory the schema describes.
* test: type the ObjectMiddleware round-trip context
`ObjectMiddleware`'s serialize/deserialize take a context carrying a logger,
and deserialize returns a value that may be a promise, so `{}` and a bare `[0]`
failed `lint:types-test` on CI.
* chore: shorten the comments the review flagged
Both new comments ran past the two-line limit AGENTS.md sets for `lib/`, and
one narrated the code it replaced. The changeset entry now fits the 80-character
limit while still naming the option.
* style: run prettier over CHANGELOG.md
The entry for #20889 padded a double-backtick code span with spaces, which
`fmt:check` rejects, so `lint` is red on main and on every branch cut from it.
* test: pin the round-trip with strict equality
`toEqual` ignores an undefined property and a swapped prototype, so the two
cases the dispatch table exists for — `d: undefined` and the null-prototype
object — would have passed even if the format dropped them.
* test: use strict equality for the rest of the round-trip assertions
The buffer case is the one that mattered: `toEqual` would have accepted a
plain Uint8Array where the format restores a Buffer.1 parent 3a7c0e6 commit c150225
12 files changed
Lines changed: 318 additions & 111 deletions
File tree
- .changeset
- lib
- serialization
- test
- configCases/cache-dependencies/managed-paths-regexp
- node_modules/package
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
792 | | - | |
| 792 | + | |
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1207 | 1207 | | |
1208 | 1208 | | |
1209 | 1209 | | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
1210 | 1219 | | |
1211 | 1220 | | |
1212 | 1221 | | |
| |||
2663 | 2672 | | |
2664 | 2673 | | |
2665 | 2674 | | |
2666 | | - | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
2667 | 2679 | | |
2668 | 2680 | | |
2669 | 2681 | | |
| |||
3921 | 3933 | | |
3922 | 3934 | | |
3923 | 3935 | | |
3924 | | - | |
| 3936 | + | |
| 3937 | + | |
| 3938 | + | |
| 3939 | + | |
3925 | 3940 | | |
3926 | 3941 | | |
3927 | 3942 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
| 464 | + | |
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| 576 | + | |
| 577 | + | |
576 | 578 | | |
577 | 579 | | |
578 | 580 | | |
579 | 581 | | |
580 | 582 | | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
586 | 587 | | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
595 | 609 | | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | 610 | | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
611 | 620 | | |
612 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
613 | 631 | | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
619 | 650 | | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
626 | 654 | | |
627 | | - | |
628 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
629 | 661 | | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
634 | 667 | | |
635 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
636 | 676 | | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
| 677 | + | |
| 678 | + | |
642 | 679 | | |
643 | | - | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
644 | 684 | | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
665 | 691 | | |
666 | | - | |
667 | | - | |
668 | 692 | | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
| 693 | + | |
676 | 694 | | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
| 695 | + | |
| 696 | + | |
681 | 697 | | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
682 | 702 | | |
683 | | - | |
684 | | - | |
685 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
686 | 706 | | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
691 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
692 | 725 | | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
| 726 | + | |
705 | 727 | | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
| 728 | + | |
| 729 | + | |
710 | 730 | | |
711 | 731 | | |
712 | 732 | | |
| |||
0 commit comments