Skip to content

Optimize syntax highlighting performance #20

Closed

Description

@unhappychoice

Overview

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:

  1. Calculate highlights once for old_content when switching to the file
  2. Calculate highlights once for new_content after all changes are complete
  3. 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
  • Smoother animation with less CPU usage
  • Better scalability for large files

Related

Part of performance optimization efforts

Activity

  1. added a commit that references this issue on Nov 9, 2025
    0c6f38d
  2. added this to the v0.1.0 milestone on Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions