Skip to content

Comment "Reply" freezes the tab on large documents (full-doc decoration rebuild) #54

Description

@mmoren10

Summary

On a large document (~132 KB / ~14k lines), clicking Reply on a comment freezes the tab (Chrome "Page Unresponsive"). Loading and reading the same document are fine, and the identical reply flow on a small document is instant. The cause appears to be a full-document decoration rebuild triggered on comment-state changes.

Environment

  • Self-hosted, editor loaded from /d/<slug>
  • Document: single doc, ~132 KB markdown, ~14k lines
  • Version: fb25787

Symptom

  1. Open a large doc, scroll to a paragraph with a comment.
  2. Click Reply (or start typing a reply).
  3. Tab main thread blocks → "Page Unresponsive". Small docs: no freeze.

Suspected cause

src/editor/plugins/comments.ts rebuilds decorations across the entire document on comment changes:

  • comments.ts:123doc.descendants((node, pos) => { … }) walks every node.
  • comments.ts:369return DecorationSet.create(state.doc, decorations); rebuilds the full set.

On a ~14k-node document this O(nodes) rebuild runs synchronously in the comment/reply path and blocks the main thread. Reply and resolve don't change comment anchors, so a full anchor rescan shouldn't be needed for them.

Suggested fix

  • Map the existing DecorationSet through the transaction (decorationSet.map(tr.mapping, tr.doc)) and only recompute ranges affected by anchor changes, instead of rebuilding from scratch on every comment-state change.
  • For reply/resolve (no anchor change), skip decoration recomputation entirely.

Found while debugging a self-hosted instance with Claude Code. Happy to test a patch against the large doc that reproduces it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions