Skip to content

perf(editor): don't slice the markdown suffix per-character in the rich-editor preprocessor - #9887

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-markdown-slice
Jul 22, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-markdown-slice

Conversation

@nwparker

@nwparker nwparker commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What

encodeRawMarkdownHtmlForRichEditor — the preprocessor on the rich Markdown editor open path — computed normalizedContent.slice(index) on every character of the document, but that suffix string is only read at line starts (the fenced-code-block detection match). Move the slice inside the if (isLineStart) branch.

Byte-identical output; O(lines) suffix allocations instead of O(chars).

ELI5

To notice where code fences start, the editor was making a fresh copy of "the rest of the document from here" for every single character — but it only looks at that copy at the start of each line. Now it only makes the copy at line starts.

Proof of zero regression

  • lineRest is used only inside the if (isLineStart) block (the fence match), so the value computed is identical — pure behavior-preserving.
  • Tests: the codec's round-trip + HTML-superscript + link-shortcut + programmatic-sync suites 62/62 pass (incl. markdown-round-trip.test.ts, the byte-fidelity test). typecheck:web clean.

Proof of perf improvement

Isolated micro-benchmark on a 2,000-line (~150 KB) doc: 76× fewer suffix allocations (152,889 → 2,000), and the isolated slice loop drops from ~0.66 ms to ~0.29 ms/run.

Honest scope

Surfaced while investigating #7056 (rich editor slow to open long docs). This removes obvious per-character allocation waste, but it is a small contribution — the dominant cost of #7056's 3–5s open is the full TipTap/ProseMirror document construction, which is a separate, larger change (being coordinated with the issue's assignee). Shipping this independently as a clean, free win.

Made with Orca 🐋

encodeRawMarkdownHtmlForRichEditor (the rich-editor open preprocessor) computed
normalizedContent.slice(index) on every character of the document, but the result
is only read at line starts (the fence-detection match). Move the slice inside the
isLineStart branch — byte-identical output, but O(lines) suffix allocations instead
of O(chars) (76x fewer on a 2000-line doc). Surfaced while investigating #7056; a
small allocation cleanup on the rich-editor open path, not the dominant cost.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aa394fa3-6e9c-4dbb-ba63-fe21973faaf3

📥 Commits

Reviewing files that changed from the base of the PR and between e600600 and 756aabd.

📒 Files selected for processing (1)
  • src/renderer/src/components/editor/raw-markdown-html.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit dfbd9ba into main Jul 22, 2026
2 checks passed
@nwparker
nwparker deleted the nwparker/perf-markdown-slice branch July 22, 2026 10:30
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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