Skip to content

Commit

Permalink
Generate a monomorphic version .createReadOnly for each class model
Browse files Browse the repository at this point in the history
The VScode Deopt explorer showed that `.createReadOnly` inside the class
model `register` function was getting deoptimized because it closes over
too-wide a variety of `klass` variable references. We're closing over it
so it is correct, but to v8, the callsite is still the same I guess, so
it has to deoptimize to pull the right value for the closure!

Removing this deoptimization added about 10% to the large root benchmark
for me!
  • Loading branch information
airhorns committed Nov 13, 2023
1 parent 9e65af5 commit 5f37e08
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/fast-instantiator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyType>, an
[$memos] = null;
[$memoizedKeys] = null;
static createReadOnly = (snapshot, env) => {
const context = {
referenceCache: new Map(),
referencesToResolve: [],
env,
};
const instance = new ${this.model.name}(snapshot, context, null);
for (const resolver of context.referencesToResolve) {
resolver();
}
return instance;
};
constructor(
snapshot,
context,
Expand Down

0 comments on commit 5f37e08

Please sign in to comment.