Skip to content

Commit c5795b8

Browse files
committed
perf: defer _cachedSize allocation to first size() call
The constructors of RawSource, OriginalSource and SourceMapSource preallocated `this._cachedSize = undefined` so that size() has a stable hidden-class slot to write to. That made every construction pay for memoization machinery regardless of whether .size() was ever called, showing up on CodSpeed as a ~12% regression on `cached-source: new CachedSource()` and 5-13% on several `source-map-source: new (*)` benchmarks. The size() overrides already guard on `this._cachedSize !== undefined`, which correctly handles missing properties. Drop the eager assignment and let the field be created on the first size() call. This keeps the size()/streamChunks() improvements from PR #199 (e.g. ~8x on a one-shot `new SMS().size()`) while erasing the construction regression. https://claude.ai/code/session_01LZbaaPrnDTu6y7s4nK4cJz
1 parent fdb229e commit c5795b8

3 files changed

Lines changed: 0 additions & 15 deletions

File tree

lib/OriginalSource.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class OriginalSource extends Source {
4949
* @type {string}
5050
*/
5151
this._name = name;
52-
/**
53-
* @private
54-
* @type {undefined | number}
55-
*/
56-
this._cachedSize = undefined;
5752
}
5853

5954
getName() {

lib/RawSource.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class RawSource extends Source {
6060
} else {
6161
throw new TypeError("argument 'value' must be either string or Buffer");
6262
}
63-
/**
64-
* @private
65-
* @type {undefined | number}
66-
*/
67-
this._cachedSize = undefined;
6863
}
6964

7065
isBuffer() {

lib/SourceMapSource.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ class SourceMapSource extends Source {
113113
: undefined;
114114

115115
this._removeOriginalSource = removeOriginalSource;
116-
/**
117-
* @private
118-
* @type {undefined | number}
119-
*/
120-
this._cachedSize = undefined;
121116
}
122117

123118
/**

0 commit comments

Comments
 (0)