Commit 88e5e6d
committed
Avoid reading outside of collection bounds
Consider the following collection:
const array = ['a', 'b', 'c'];
Retrieving `array[0]` can be done relatively quickly. However, when the property doesn’t exist on the receiver, JavaScript engines must continue to look up the prototype chain until either the property is found or the chain ends. This is inherently slower than *not* doing any prototype chain lookups. Retrieving an out-of-bounds index, e.g. `array[3]`, triggers this scenario, resulting in decreased performance.
This patch changes the way some loops are written to avoid running into the slow case unnecessarily.1 parent f6bd902 commit 88e5e6d
4 files changed
Lines changed: 31 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
| 661 | + | |
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
| 674 | + | |
674 | 675 | | |
675 | | - | |
| 676 | + | |
| 677 | + | |
676 | 678 | | |
677 | 679 | | |
678 | 680 | | |
| |||
702 | 704 | | |
703 | 705 | | |
704 | 706 | | |
705 | | - | |
| 707 | + | |
| 708 | + | |
706 | 709 | | |
707 | 710 | | |
708 | 711 | | |
709 | | - | |
| 712 | + | |
| 713 | + | |
710 | 714 | | |
711 | 715 | | |
712 | 716 | | |
| |||
1054 | 1058 | | |
1055 | 1059 | | |
1056 | 1060 | | |
1057 | | - | |
| 1061 | + | |
| 1062 | + | |
1058 | 1063 | | |
1059 | 1064 | | |
1060 | 1065 | | |
1061 | 1066 | | |
1062 | 1067 | | |
1063 | 1068 | | |
1064 | 1069 | | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
1068 | 1074 | | |
1069 | 1075 | | |
1070 | 1076 | | |
| |||
0 commit comments