@samitouri / QOS-React-2 / commits / 7e10c51532

Put optimizations in this stack behind a feature flag

Wraps all the optimizations from this stack behind a feature flag so we can quickly disable if there are problems when integrating.

Joe Savona committed May 18, 2023 at 16:20 UTC 7e10c51532225d26ab5f2c1c9085ca3656c29c1d
5 files changed +25 -16
compiler/forget/packages/snap/src/compiler-worker.ts
+1
@@ -138,6 +138,7 @@ export async function compile(
138 ],
139 ]),
140 validateHooksUsage: true,
141 + enableFunctionCallSignatureOptimizations: true,
142 inlineUseMemo: true,
143 memoizeJsxElements,
144 },
compiler/forget/src/HIR/Environment.ts
+4
@@ -41,6 +41,7 @@ export type EnvironmentConfig = Partial<{
41 memoizeJsxElements: boolean;
42 validateHooksUsage: boolean;
43 inlineUseMemo: boolean;
44 + enableFunctionCallSignatureOptimizations: boolean;
45 }>;
46
47 export class Environment {
@@ -49,6 +50,7 @@ export class Environment {
50 #nextIdentifer: number = 0;
51 #nextBlock: number = 0;
52 validateHooksUsage: boolean;
53 + enableFunctionCallSignatureOptimizations: boolean;
54 #contextIdentifiers: Set<t.Identifier>;
55
56 constructor(
@@ -73,6 +75,8 @@ export class Environment {
75 this.#globals = DEFAULT_GLOBALS;
76 }
77 this.validateHooksUsage = config?.validateHooksUsage ?? false;
78 + this.enableFunctionCallSignatureOptimizations =
79 + config?.enableFunctionCallSignatureOptimizations ?? false;
80 this.#contextIdentifiers = contextIdentifiers;
81 }
82
compiler/forget/src/Inference/InferReferenceEffects.ts
+3 -4
@@ -718,10 +718,9 @@ function inferBlock(
718 break;
719 }
720
721 - const signature = getFunctionCallSignature(
722 - env,
723 - instrValue.callee.identifier.type
724 - );
721 + const signature = env.enableFunctionCallSignatureOptimizations
722 + ? getFunctionCallSignature(env, instrValue.callee.identifier.type)
723 + : null;
724
725 const effects =
726 signature !== null ? getFunctionEffects(instrValue, signature) : null;
compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts
+16 -12
@@ -248,22 +248,26 @@ function mayAllocate(env: Environment, value: InstructionValue): boolean {
248 return false;
249 }
250 case "CallExpression": {
251 - const signature = getFunctionCallSignature(
252 - env,
253 - value.callee.identifier.type
254 - );
255 - if (signature !== null) {
256 - return signature.returnType.kind !== "Primitive";
251 + if (env.enableFunctionCallSignatureOptimizations) {
252 + const signature = getFunctionCallSignature(
253 + env,
254 + value.callee.identifier.type
255 + );
256 + if (signature !== null) {
257 + return signature.returnType.kind !== "Primitive";
258 + }
259 }
260 return true;
261 }
262 case "MethodCall": {
261 - const signature = getFunctionCallSignature(
262 - env,
263 - value.receiver.identifier.type
264 - );
265 - if (signature !== null) {
266 - return signature.returnType.kind !== "Primitive";
263 + if (env.enableFunctionCallSignatureOptimizations) {
264 + const signature = getFunctionCallSignature(
265 + env,
266 + value.receiver.identifier.type
267 + );
268 + if (signature !== null) {
269 + return signature.returnType.kind !== "Primitive";
270 + }
271 }
272 return true;
273 }
compiler/forget/src/__tests__/compiler-test.ts
+1
@@ -59,6 +59,7 @@ describe("React Forget", () => {
59 ]),
60 validateHooksUsage: true,
61 inlineUseMemo: options.environment?.inlineUseMemo ?? false,
62 + enableFunctionCallSignatureOptimizations: true,
63 },
64 logger: null,
65 gating: options.gating,