Repository navigation
perf: optimize syntax highlighting performance - #21
Conversation
close: #20 - Pre-calculate highlights for old and new content at file switch - Remove intermediate UpdateHighlights calls during animation - Use cursor_line to determine which highlights to display: - Lines before cursor: new_highlights (edited) - Cursor line: no highlights (currently editing) - Lines after cursor: old_highlights (unedited, with line offset) - Track line offset for correct highlight mapping - Refactor editor.rs with smaller, focused functions Performance improvement: O(n) → O(2) highlight calculations per file 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. WalkthroughRefactors highlighting to precompute old/new file highlights and per-line byte offsets at SwitchFile. EditorBuffer gained fields for old/new highlights, content lines, and line offsets; AnimationStep::SwitchFile now carries old_content and new_content. UpdateHighlights was removed. EditorPane rendering rewritten to consume precomputed highlights and a line_offset tracked by AnimationEngine. Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant AnimationEngine
participant Highlighter
participant EditorBuffer
participant EditorPane
Note over App,AnimationEngine: New flow — highlights computed twice per file
App->>AnimationEngine: SwitchFile(old_content, new_content, path)
AnimationEngine->>Highlighter: calc highlights for old_content
AnimationEngine->>Highlighter: calc highlights for new_content
AnimationEngine->>EditorBuffer: store old/new highlights, lines, offsets
EditorPane->>EditorBuffer: read precomputed highlights & lines
loop Per-line edits (InsertLine/DeleteLine/InsertChar)
App->>AnimationEngine: edit step
AnimationEngine->>AnimationEngine: adjust line_offset
AnimationEngine->>EditorBuffer: update visible content (no highlight recalculation)
EditorPane->>EditorBuffer: select highlights by line & offset
EditorPane->>EditorPane: render line with highlights & cursor
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/animation.rs(9 hunks)src/panes/editor.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/panes/editor.rs (2)
src/ui.rs (2)
render(173-210)new(42-58)src/animation.rs (2)
new(47-59)new(189-209)
src/animation.rs (2)
src/ui.rs (1)
new(42-58)src/syntax/mod.rs (1)
new(86-95)
Pre-calculate line byte offsets from original content to handle CRLF correctly. str::lines() removes line endings, causing byte offset drift when using line.len() + 1. Changes: - Add old_content_line_offsets and new_content_line_offsets to EditorBuffer - Implement calculate_line_offsets function that scans for '\n' bytes - Update calculate_byte_offset to use pre-calculated offsets - Rename select_highlights_and_content to select_highlights_and_offsets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/animation.rs(9 hunks)src/panes/editor.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/panes/editor.rs (2)
src/ui.rs (2)
render(173-210)new(42-58)src/animation.rs (2)
new(50-64)new(196-216)
Replace repeated chars().take(char_idx) iteration with cumulative relative_byte tracking in apply_highlights function. Before: O(n²) - recalculating byte offset for each character After: O(n) - accumulating byte offset incrementally 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The file `-` at the repo root was a 533KB `cargo llvm-cov` text report that landed in `gnhf #21` when the report was redirected to a literal `-` filename (instead of stdout). It is not referenced by any code or CI, and its contents are reproducible on demand from `cargo llvm-cov`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #20
Closes #23
Summary
Performance Improvement
Implementation Details
Highlight Selection Strategy
new_highlights(already edited)old_highlights(not yet edited, with line offset)Line Offset Tracking
CRLF Fix
Refactoring
highlight_lineinto focused functions:select_highlights_and_offsets: Choose appropriate highlights and offsetscalculate_byte_offset: Compute byte offset with line offsetfilter_line_highlights: Filter highlights for current lineapply_highlights: Apply highlighting with cursor supportget_char_color: Get color for characterTest Plan
🤖 Generated with Claude Code
Summary by CodeRabbit