Skip to content

Avoid cloning keyed comprehensions without moves#4328

Open
preciz wants to merge 1 commit into
phoenixframework:mainfrom
preciz:perf/skip-unneeded-keyed-clone
Open

Avoid cloning keyed comprehensions without moves#4328
preciz wants to merge 1 commit into
phoenixframework:mainfrom
preciz:perf/skip-unneeded-keyed-clone

Conversation

@preciz

@preciz preciz commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@SteffenDE I'm not familiar with the JS side of things but this seems like a small diff for a good gain in performance.

Assisted by: GPT 5.6 Sol - Codex

Clone keyed state only when a diff moves entries. Stable-position
updates never read another old position, so they can merge in place
instead of copying the full cached render tree.

Keyed entries are encoded as:

  • kc: resulting entry count
  • object: new entry or same-position diff
  • number: old index for a move without a diff
  • [old_index, diff]: move with a diff

Only the two move encodings read old positions and need a snapshot
before mutation. Nested keyed diffs apply the same rule, cloning only
the subtree that moves.

Chromium 150 merge-only timings (median of seven calibrated samples;
DOM patching excluded):

  • 1,000/10,000 compact two-field rows: 0.435/4.29 ms -> 0.001 ms
  • 1,000/10,000 rich rows (eight fields, four children): 3.94/47.5 ms -> 0.001 ms

Stable keyed merges inside LiveComponents dropped from two tree clones
to one, making merge-only benchmarks about 2x faster. Reordering
entries still needs the move-safety clone and showed no material change.

Assisted by: GPT 5.6 Sol - Codex

Clone keyed state only when a diff moves entries. Stable-position
updates never read another old position, so they can merge in place
instead of copying the full cached render tree.

Keyed entries are encoded as:

- `kc`: resulting entry count
- object: new entry or same-position diff
- number: old index for a move without a diff
- `[old_index, diff]`: move with a diff

Only the two move encodings read old positions and need a snapshot
before mutation. Nested keyed diffs apply the same rule, cloning only
the subtree that moves.

Chromium 150 merge-only timings (median of seven calibrated samples;
DOM patching excluded):

- 1,000/10,000 compact two-field rows: 0.435/4.29 ms -> 0.001 ms
- 1,000/10,000 rich rows (eight fields, four children):
  3.94/47.5 ms -> 0.001 ms

Stable keyed merges inside LiveComponents dropped from two tree clones
to one, making merge-only benchmarks about 2x faster. Reordering
entries still needs the move-safety clone and showed no material change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant