Commit 03fed1e
committed
perf: fully inline _getCachedSource in source() and split CachedSource ctor
Two follow-ups to keep CodSpeed happy:
1. `source()` previously inlined only the warm `_cachedSource` check
and still called `_getCachedSource()` on cold reads, which under the
interpreter (CodSpeed's simulation mode) pays a function-call stack
frame plus a redundant re-check of `_cachedSource`. Inline the whole
helper body so both warm and cold paths stay branchless-to-call.
Local --no-opt: cold `new CachedSource(RawSource).source()`
drops 534 -> 477 ns/op (+12% vs main).
2. The constructor was evaluating `cachedData ? cachedData.X : undefined`
once per cached-data field (five separate ternaries). Replace with a
single branch on `cachedData` so construction pays one conditional
instead of five. Local --no-opt:
`new CachedSource(new RawSource(…))` drops 431 -> 375 ns/op (+13%
vs main), erasing the -11% regression CodSpeed showed on
`cached-source: new CachedSource()`.
`_getCachedSource()` stays on the class because `buffer()`,
`streamChunks()` and `getCachedData()` still call it; only `source()`
had a hot enough caller to justify duplicating the body.
https://claude.ai/code/session_01LZbaaPrnDTu6y7s4nK4cJz1 parent 3191486 commit 03fed1e
1 file changed
Lines changed: 51 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | 130 | | |
136 | 131 | | |
137 | 132 | | |
138 | 133 | | |
139 | 134 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
160 | 172 | | |
161 | 173 | | |
162 | 174 | | |
| |||
212 | 224 | | |
213 | 225 | | |
214 | 226 | | |
215 | | - | |
216 | | - | |
217 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
218 | 230 | | |
219 | | - | |
220 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
221 | 242 | | |
222 | 243 | | |
223 | 244 | | |
| |||
0 commit comments