Skip to content

Commit a75e672

Browse files
author
MesTTo
committed
perf(core): short-circuit subTokens/resolveStates/wrapStates when world has no tokens/states (oracle 61->47ms, 270/270)
1 parent e7ad9c3 commit a75e672

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

packages/core/src/eval.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function spaceName(w: World, a: Atom): string | undefined {
242242
return r.kind === "sym" ? r.name : undefined;
243243
}
244244
function resolveStates(w: World, a: Atom): Atom {
245+
if (w.store.size === 0) return a; // no state cells: identity, skip the tree clone (hot path)
245246
if (a.kind === "expr") {
246247
if (opOf(a) === "State" && a.items.length === 2) {
247248
const g = a.items[1]!;
@@ -252,11 +253,13 @@ function resolveStates(w: World, a: Atom): Atom {
252253
return a;
253254
}
254255
function subTokens(w: World, a: Atom): Atom {
256+
if (w.tokens.size === 0) return a; // no bind! tokens: identity, skip the tree clone (hot path)
255257
if (a.kind === "sym") return w.tokens.get(a.name) ?? a;
256258
if (a.kind === "expr") return expr(a.items.map((x) => subTokens(w, x)));
257259
return a;
258260
}
259261
function wrapStates(w: World, a: Atom): Atom {
262+
if (w.store.size === 0) return a; // no state cells: identity, skip the tree clone (hot path)
260263
if (a.kind === "expr") {
261264
if (opOf(a) === "State" && a.items.length === 2) {
262265
const g = a.items[1]!;

0 commit comments

Comments
 (0)