Skip to content

[diffs/edit] avoid full retokenization on newline inserts - #1057

Merged
ije merged 3 commits into
mainfrom
ije/improve-tokenzier
Aug 6, 2026
Merged

[diffs/edit] avoid full retokenization on newline inserts#1057
ije merged 3 commits into
mainfrom
ije/improve-tokenzier

Conversation

@ije

@ije ije commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Fixes high memory usage when inserting newlines by reusing shifted syntax states after tokenization reconverges.

The testing shows reducing the Enter-key path from 100 dirty lines and 6.9 ms of tokenization to 2 dirty lines and 0.5 ms.

@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Aug 5, 2026 2:36pm
pierre-docs-diffshub Ready Ready Preview Aug 5, 2026 2:36pm
pierre-docs-trees Ready Ready Preview Aug 5, 2026 2:36pm
pierrejs-diff-demo Ready Ready Preview Aug 5, 2026 2:36pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed2fcc4db3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/diffs/src/editor/tokenizer.ts Outdated
Comment on lines +425 to +426
const canReuseShiftedStates =
hostRealignsRows && !canReuseCachedStates && dirtyStart >= startingLine;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't reuse shifted states for net-zero structural edits

When one applied change both inserts and deletes lines so the deltas cancel, change.lineDelta is 0 but canReuseCachedStates is false. This branch now lets non-diff editors settle after the first changed range and jump to the next one, omitting the shifted lines between ranges from dirtyLines; #rerender only runs applyDocumentChange/row realignment when the net line count changes, so those intervening rendered rows and cache entries keep old text after a net-zero multi-edit such as inserting a newline above line 10 and deleting one above line 20 in the same applyEdits batch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 52c1014

@amadeus amadeus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sick!

@ije
ije merged commit 307d423 into main Aug 6, 2026
8 checks passed
@ije
ije deleted the ije/improve-tokenzier branch August 6, 2026 01:52
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.

2 participants