fix(javascript): stop replaying earlier writes for each object property write

Repeated property writes to one object made member-mutation collection
cubic. Each write evaluated its target binding to rule out a primitive,
and every evaluation folded all earlier mutation paths, copying every
slot once per path. 2,000 writes to one object took 27 s and 4,000 took
203 s.

- A recorded write always leaves a non-primitive binding value, so only
  the first write to a binding needs the primitive check.
- Apply mutation paths per slot in one pass with the same ordering
  semantics instead of one full slot copy per path.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-10-10 14:04:31 +08:00
1 parent 66863b609f
commit 1ec490f361
4 files changed
+106 -48

No files matched your search

@@ -590,3 +590,24 @@ describe("property mutations through TypeScript satisfies aliases", () => {
).toEqual({ status: "literal", value: "TOKEN" });
});
});
describe("property mutation collection on minified bundles", () => {
it("records each write to one object without replaying earlier writes", () => {
const writes = Array.from(
{ length: 2000 },
(_, index) => `source.p${index} = ${index};`,
).join(" ");
const start = performance.now();
const value = resultValue(
`const source = { token: "TOKEN" }; ${writes} return [source.token, source.p1999];`,
);
expect(performance.now() - start).toBeLessThan(2000);
expect(value).toMatchObject({
status: "array",
items: [
{ value: { status: "literal", value: "TOKEN" } },
{ value: { status: "unknown" } },
],
});
}, 30000);
});