Repository navigation
fix: #3211 avoid quadratic search highlighting in large paragraphs - #5856
Merged
Merged
Conversation
8 of 13 tasks
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified, and all approval-readiness assessments support approval.
No open issues 🎉
What changed in this PR
This pull request fixes quadratic search highlighting for large paragraphs by applying highlights after tokenization and using efficient range lookup.
Changes:
- Adds ordered-range binary lookup with early termination.
- Preserves fallback handling for unordered ranges.
- Adds performance and correctness regression coverage for search flows and range edge cases.
| File | Description |
|---|---|
packages/muya/src/inlineRenderer/searchHighlights.ts |
Implements optimized search-range intersection and annotation. |
packages/muya/src/inlineRenderer/lexer.ts |
Applies highlights through the optimized post-tokenization path. |
packages/muya/src/inlineRenderer/__tests__/searchHighlights3211.spec.ts |
Adds performance-budget and correctness regression tests. |
Review effort: Lite
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3211
Summary
Searching a large paragraph with many matches checks every highlight against every inline token. A 1500-line paragraph with one match per line performs 22.5 million range reads, so searching and moving between matches can stall the renderer.
Move search annotation into
applySearchHighlights, separating token-tree traversal, range intersections and binary lookup from lexing. Use binary lookup to find the first candidate highlight for each token, then stop after the token's range. Search supplies ranges with nondecreasing starts and ends, including after grapheme alignment. Document that input contract and test it at the match producer so rendering can use binary lookup directly. Add regression coverage for the 1500-line search/navigation/replacement/clear flow, a deterministic range-access budget, and nested tokens, ordered overlapping ranges and zero-width matches.Type of change
Test plan
pnpm -C packages/muya test— 2850 tests in 302 files passed.pnpm -C packages/muya test:spec— 1347 conformance tests passed.pnpm -C packages/muya check-circular— passed.pnpm run lint— passed with existing warnings.pnpm run typecheck— passed.pnpm -C packages/muya lint:types— passed.Notes for reviewers
Measured against develop commit
55d19dc0on the same macOS ARM64 machine using Node 22.22.3 and happy-dom. The fixture repeats a line containing boldneedleand inlinecode, with one search hit per line in a single paragraph. The versions alternate execution order; each measurement uses two warmups and the median of seven samples.The full search and next-match measurements include simulated DOM rendering. They are comparative benchmark results, not Electron UI latency measurements. This change addresses the confirmed search-highlighting bottleneck in #3211; the original report's general editing slowdown across platforms has not been fully verified.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.