Commit c5795b8
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_01LZbaaPrnDTu6y7s4nK4cJz1 parent fdb229e commit c5795b8
3 files changed
Lines changed: 0 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | 52 | | |
58 | 53 | | |
59 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | 63 | | |
69 | 64 | | |
70 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 116 | | |
122 | 117 | | |
123 | 118 | | |
| |||
0 commit comments