Repository navigation
perf(editor): don't slice the markdown suffix per-character in the rich-editor preprocessor - #9887
Conversation
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]>
|
Warning Review limit reached
Next review available in: 11 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
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. Comment |
…ch-editor preprocessor (stablyai#9887) Co-authored-by: Orca <[email protected]>
What
encodeRawMarkdownHtmlForRichEditor— the preprocessor on the rich Markdown editor open path — computednormalizedContent.slice(index)on every character of the document, but that suffix string is only read at line starts (the fenced-code-block detectionmatch). Move the slice inside theif (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
lineRestis used only inside theif (isLineStart)block (the fencematch), so the value computed is identical — pure behavior-preserving.markdown-round-trip.test.ts, the byte-fidelity test).typecheck:webclean.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 🐋