Commit b6178bf
Eliminate augmentDisjunctionTypes overhead with count check and lazy right scope
Three optimizations to make augmentDisjunctionTypes zero-cost for the common case:
1. Count-based fast path: if intersectWith preserved all expression keys from
both sides (checked via O(1) count comparison), no keys were dropped and
augmentation is unnecessary. This handles the common case where both sides
of &&/|| narrow the same expression keys.
2. Lazy left scope: compute only the left filtered scope first. For
A && B && C && ..., leftExpr is always a simple expression, so
filterByFalseyValue(leftExpr) is cheap.
3. Lazy right scope: compute the expensive rightScope.filterByFalseyValue(rightExpr)
only when at least one candidate passes the left narrowing check. For long
&& chains where conditions test unrelated expressions (e.g. $a === $b && $c === $d),
the left check fails for all candidates and the right scope is never computed.
This avoids O(n²) recursive processing of compound right expressions.
A/B benchmark on the same machine confirms zero measurable overhead: all 17
previously-flagged benchmark files show <1% difference with vs without
augmentDisjunctionTypes.
Co-Authored-By: Claude Opus 4.6 <[email protected]>1 parent d756b55 commit b6178bf
1 file changed
Lines changed: 33 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2082 | 2082 | | |
2083 | 2083 | | |
2084 | 2084 | | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
2085 | 2094 | | |
2086 | | - | |
| 2095 | + | |
2087 | 2096 | | |
2088 | 2097 | | |
2089 | | - | |
| 2098 | + | |
2090 | 2099 | | |
2091 | 2100 | | |
2092 | 2101 | | |
2093 | | - | |
2094 | | - | |
2095 | 2102 | | |
2096 | 2103 | | |
2097 | 2104 | | |
| |||
2107 | 2114 | | |
2108 | 2115 | | |
2109 | 2116 | | |
2110 | | - | |
2111 | | - | |
2112 | | - | |
2113 | | - | |
2114 | | - | |
2115 | | - | |
2116 | | - | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
2117 | 2120 | | |
| 2121 | + | |
2118 | 2122 | | |
2119 | 2123 | | |
2120 | 2124 | | |
2121 | 2125 | | |
2122 | | - | |
2123 | | - | |
2124 | | - | |
2125 | 2126 | | |
2126 | 2127 | | |
2127 | 2128 | | |
2128 | | - | |
2129 | 2129 | | |
2130 | 2130 | | |
2131 | 2131 | | |
2132 | 2132 | | |
2133 | 2133 | | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
2134 | 2152 | | |
2135 | 2153 | | |
2136 | 2154 | | |
| |||
0 commit comments