Skip to content

Commit 4b89362

Browse files
Fix performance regressions with lazy symbol caching
- Replace eager symbol pre-computation with lazy caching - Fix inconsistency between cached and Symbol.for() usage - Update outerClosureStatements to use Symbol.for() in generated code - Update fast-instantiator to use Symbol.for() consistently - Maintain symbol caching benefits while eliminating instantiation overhead Co-Authored-By: Harry Brundage <[email protected]>
1 parent dca63d5 commit 4b89362

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/fast-getter.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,32 @@ export class FastGetBuilder {
2828

2929
this.memoSymbols = new Map();
3030
this.snapshotSymbols = new Map();
31-
for (const property of this.memoizableProperties) {
32-
this.memoSymbols.set(property, Symbol.for(this.memoSymbolName(property)));
33-
this.snapshotSymbols.set(property, Symbol.for(this.snapshottedViewInputSymbolName(property)));
34-
}
3531
}
3632

3733
memoSymbolName(property: string) {
3834
return `mqt/${property}-memo`;
3935
}
4036

4137
getMemoSymbol(property: string) {
42-
return this.memoSymbols.get(property)!;
38+
let symbol = this.memoSymbols.get(property);
39+
if (!symbol) {
40+
symbol = Symbol.for(this.memoSymbolName(property));
41+
this.memoSymbols.set(property, symbol);
42+
}
43+
return symbol;
4344
}
4445

4546
snapshottedViewInputSymbolName(property: string) {
4647
return `mqt/${property}-svi-memo`;
4748
}
4849

4950
getSnapshotSymbol(property: string) {
50-
return this.snapshotSymbols.get(property)!;
51+
let symbol = this.snapshotSymbols.get(property);
52+
if (!symbol) {
53+
symbol = Symbol.for(this.snapshottedViewInputSymbolName(property));
54+
this.snapshotSymbols.set(property, symbol);
55+
}
56+
return symbol;
5157
}
5258

5359
outerClosureStatements(className: string) {

0 commit comments

Comments
 (0)