Commit 0270028
committed
perf: use index-based recursion to avoid array allocations
Refactor getGroupRecursive to use index-based traversal instead of array slicing, and eliminate array mutation from shift(). Previous implementation issues: - classParts.slice(1) created a new array on every recursive call, causing O(n) allocations for deep class name lookups - classParts.shift() mutated the array and moved all elements, causing O(n) element movement and potential V8 deoptimization Optimizations: - Added startIndex parameter to getGroupRecursive() to track position without array slicing - Replaced shift() with index offset calculation, eliminating array mutation - Only slice array when building classRest string for validators (less frequent path), and optimize with early check for startIndex === 0 This maintains monomorphic call sites (important for V8 optimization) while significantly reducing memory allocations during class group lookups. Benchmark results show ~1.6% improvement on 'collection without cache' benchmark (when combined with fast path optimization).1 parent 8ffbd67 commit 0270028
1 file changed
+12
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
| |||
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
| 88 | + | |
90 | 89 | | |
91 | 90 | | |
92 | | - | |
| 91 | + | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | | - | |
| 96 | + | |
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | | - | |
| 100 | + | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
| |||
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
111 | 114 | | |
112 | 115 | | |
113 | 116 | | |
| |||
0 commit comments