107
* conditional node with an aliased dep promotes to aliased).
108
* 4. Finally we prune scopes whose outputs weren't marked.
109
*/
110
-export function pruneNonEscapingScopes(
111
- fn: ReactiveFunction,
112
- options: MemoizationOptions
113
-): void {
110
+export function pruneNonEscapingScopes(fn: ReactiveFunction): void {
111
/*
112
* First build up a map of which instructions are involved in creating which values,
113
* and which values are returned.
120
state.declare(param.place.identifier.id);
121
}
122
}
126
- visitReactiveFunction(
127
- fn,
128
- new CollectDependenciesVisitor(fn.env, options),
129
- state
130
- );
123
+ visitReactiveFunction(fn, new CollectDependenciesVisitor(fn.env), state);
124
125
// log(() => prettyFormat(state));
126
140
141
export type MemoizationOptions = {
142
memoizeJsxElements: boolean;
143
+ forceMemoizePrimitives: boolean;
144
};
145
146
// Describes how to determine whether a value should be memoized, relative to dependees and dependencies
462
case "JSXText":
463
case "BinaryExpression":
464
case "UnaryExpression": {
465
+ const level = options.forceMemoizePrimitives
466
+ ? MemoizationLevel.Memoized
467
+ : MemoizationLevel.Never;
468
return {
469
// All of these instructions return a primitive value and never need to be memoized
473
- lvalues:
474
- lvalue !== null
475
- ? [{ place: lvalue, level: MemoizationLevel.Never }]
476
- : [],
470
+ lvalues: lvalue !== null ? [{ place: lvalue, level }] : [],
471
rvalues: [],
472
};
473
}
583
}
584
case "ComputedLoad":
585
case "PropertyLoad": {
586
+ const level = options.forceMemoizePrimitives
587
+ ? MemoizationLevel.Memoized
588
+ : MemoizationLevel.Conditional;
589
return {
590
// Indirection for the inner value, memoized if the value is
594
- lvalues:
595
- lvalue !== null
596
- ? [{ place: lvalue, level: MemoizationLevel.Conditional }]
597
- : [],
591
+ lvalues: lvalue !== null ? [{ place: lvalue, level }] : [],
592
/*
593
* Only the object is aliased to the result, and the result only needs to be
594
* memoized if the object is
762
env: Environment;
763
options: MemoizationOptions;
764
771
- constructor(env: Environment, options: MemoizationOptions) {
765
+ constructor(env: Environment) {
766
super();
767
this.env = env;
774
- this.options = options;
768
+ this.options = {
769
+ memoizeJsxElements:
770
+ this.env.config.memoizeJsxElements && !this.env.config.enableForest,
771
+ forceMemoizePrimitives: this.env.config.enableForest,
772
+ };
773
}
774
775
override visitInstruction(