You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize syntax highlighting by calculating highlights only once for the old content and once for the new content, instead of recalculating after every line change.
Current Behavior
Currently, UpdateHighlights is called multiple times during file animation:
After file switch (animation.rs:291)
After every line deletion (animation.rs:487)
After inserting empty line (animation.rs:504)
After completing line typing (animation.rs:519)
This causes unnecessary recalculation of syntax highlighting for the entire file content after each individual change.
Proposed Optimization
Since we're animating a diff between two complete file states:
Calculate highlights once for old_content when switching to the file
Calculate highlights once for new_content after all changes are complete
Remove intermediate UpdateHighlights calls during line-by-line changes
This would reduce the number of highlight calculations from O(n) where n = number of line changes, to just 2 calculations per file.
Implementation Notes
old_content highlights should be calculated at SwitchFile step
new_content highlights should be calculated once after all hunks are processed
The incremental parsing cache in Highlighter (lines 127-139 in src/syntax/mod.rs) can still be utilized between the two full calculations
Expected Benefits
Significant performance improvement for files with many line changes
Activity
perf: optimize syntax highlighting performance