Skip to content

fix: stop serializing the whole document after every edit - #681

Merged
Azganoth merged 3 commits into
mainfrom
bug/per-edit-serialization
Oct 10, 2026
Merged

Azganoth merged 3 commits into
mainfrom
bug/per-edit-serialization

Conversation

@Azganoth

@Azganoth Azganoth commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

After each edit, once typing paused for 200 ms, Milkdown's listener plugin serialized the whole document so the session held a current copy of its Markdown, and it serialized once more when the editor was created. That blocked the main thread for about a third of a second in a 200 KB document of tables and about a second at 500 KB (#672).

The listener is removed. The session's content is now the Markdown a document was opened, created, or last saved with, and each reader that needs the current text gets it from the editor:

  • Save and moving the open document already read the editor bridge first and are unchanged.
  • Reopening the same path reloads the editor whenever the document has edits, not only when the file's text differs. The edits were discarded to reopen it, and the session's text no longer shows them.
  • An editor that lets go of an edited document that stays open hands its Markdown to the session once. A remounted editor starts from that text, and Save still writes the edits after a crash in the document surface removes the editor, because the menu bar sits outside that error boundary.
  • Folder search treated the session's text changing as its cue to search the open document again. It now waits 200 ms after a content-change signal that the editor bridge fires on each edit without reading the text.

The bridge's getMarkdown returns null instead of throwing while the editor is still being created, so these readers fall back to the session's text, which no edit can have changed yet.

Related Issue

Closes #672

Verification

  • openSession: an edited document whose session text still matches the file reloads when reopened after its edits are discarded.
  • document-screen: edits fire the content signal without changing the session's text; when the editor unmounts, the edited Markdown moves to the session and the next editor mounts with it.
  • documentWorkflows: Save writes the handed-over text once no editor holds the document, and a clean or replaced document's editor is not read.
  • folderSearchWorkflows: the open document's results follow an edit once it settles.
  • Each of these tests failed with its fix disabled. The editor tests of the listener were removed; the dirty-tracking assertions they held remain.
  • pnpm check:frontend passed after merging main.

Manually verified in a Windows 11 release build, before merging #675–#678 from main:

  1. In 205 KB and 505 KB documents of 120-row, 6-column tables, five spaced keystrokes in a cell of the middle table were each followed by no long animation frame. The keystroke's own frame, before the character painted, took 69–85 ms at 205 KB and 181–226 ms at 505 KB, mostly the input handler.
  2. The same harness on main at 7cea7b9 recorded a 636–1179 ms timer frame 230–290 ms after every keystroke at 205 KB.

Not verified: the release-build timings after merging #675–#678.

@Azganoth Azganoth added the Bug Something isn't working label Oct 10, 2026
@Azganoth Azganoth self-assigned this Oct 10, 2026
…ation

# Conflicts:
#	CHANGELOG.md
#	src/features/editor/utils/createMilkdownEditor.ts
@Azganoth
Azganoth merged commit fa9e842 into main Oct 10, 2026
3 checks passed
@Azganoth
Azganoth deleted the bug/per-edit-serialization branch October 10, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Every edit serializes the whole document

1 participant