Skip to content

perf(editor): derive heading ids from the doc instead of plugin state - #9555

Merged
mejo- merged 1 commit into
mainfrom
perf/headings
Nov 16, 2026
Merged

mejo- merged 1 commit into
mainfrom
perf/headings

Conversation

@mejo-

@mejo- mejo- commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Heading ids are now computed by getHeadings(doc), which caches the result per doc node. The headingAnchor plugin only keeps its DecorationSet, mapping it through transactions while heading ids stay the same and rebuilding it otherwise.

Anchor widgets are keyed by heading id, so ProseMirror reuses their DOM without looking up existing anchors. That lookup ran once per heading on every rebuild, making edits that change a heading id quadratic in the number of headings (~280 ms vs ~5.6 ms per keystroke with 500 headings in jsdom).
Here's the table:

Time per transaction in ms (jsdom with a mounted EditorView, average of 2 runs × 50 transactions). Document of N sections, each one <h2> followed by five paragraphs.

Typing in a heading Chromium before Chromium after Firefox before Firefox after
N=200 2.07 1.58 2.70 1.62
N=500 7.04 4.72 11.18 5.84
N=1000 22.4 13.8 38.0 16.8

Assisted-by: ClaudeCode:claude-opus-5-5

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

@mejo- mejo- self-assigned this Nov 5, 2026
@github-project-automation github-project-automation Bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Productivity team Nov 5, 2026
@nextcloud-command nextcloud-command added the AI assisted This PR contains AI-assisted commits label Nov 5, 2026
@mejo- mejo- moved this from 🧭 Planning evaluation (don't pick) to 👀 In review in 📝 Productivity team Nov 5, 2026
Comment thread src/plugins/extractHeadings.ts Resolved
Comment thread src/plugins/headingAnchor.ts Resolved
Comment thread src/plugins/headingAnchor.ts Resolved
Comment thread src/plugins/headingAnchor.ts Resolved
Comment thread src/composables/useEditorHeadings.ts Resolved
Heading ids are now computed by getHeadings(doc), which caches the
result per doc node. The headingAnchor plugin only keeps its
DecorationSet, mapping it through transactions while heading ids stay
the same and rebuilding it otherwise.

Anchor widgets are keyed by heading id, so ProseMirror reuses their DOM
without looking up existing anchors. That lookup ran once per heading
on every rebuild, making edits that change a heading id quadratic in
the number of headings (~280 ms vs ~5.6 ms per keystroke with 500
headings in jsdom).

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
@mejo-

mejo- commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

/backport to stable35

@mejo-
mejo- merged commit 27f7b83 into main Nov 16, 2026
76 of 78 checks passed
@mejo-
mejo- deleted the perf/headings branch November 16, 2026 09:19
@github-project-automation github-project-automation Bot moved this from 👀 In review to ☑️ Done in 📝 Productivity team Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review AI assisted This PR contains AI-assisted commits performance 🚀

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

3 participants