Skip to content

perf(syntax): optimize viewport highlighting#28

Open
seatedro wants to merge 1 commit into
masterfrom
highlight-diff-perf
Open

perf(syntax): optimize viewport highlighting#28
seatedro wants to merge 1 commit into
masterfrom
highlight-diff-perf

Conversation

@seatedro
Copy link
Copy Markdown
Owner

Summary

  • cache syntax source text plus parsed trees instead of full-file token spans
  • highlight only requested viewport byte ranges for syntax tiles
  • refresh affected RenderDoc style runs instead of rebuilding the whole document per tile
  • add timing logs around syntax source cache, parse, annotation, and total load time

Validation

  • direnv exec . cargo check
  • direnv exec . env XDG_DATA_HOME=/tmp/diffy-empty-data cargo test -p phosphor
  • direnv exec . cargo test syntax_refresh_updates_only_targeted_line_runs

@seatedro seatedro force-pushed the highlight-diff-perf branch from 197e385 to 6c7980e Compare May 11, 2026 09:40
Copy link
Copy Markdown

@capy-ai capy-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 1 comment

Comment thread src/apprt/services.rs
const SOURCE_BYTE_BUDGET: usize = 64 * 1024 * 1024;

let bytes = syntax.estimated_bytes().max(1);
let bytes = estimated_text_store_bytes(&source.text).max(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🟡 Medium] [🔵 Bug]

The new cache stores both text and ParsedSyntax, but eviction sizing only counts TextStore bytes. That means actual resident memory can significantly exceed SOURCE_BYTE_BUDGET, especially for large files where tree-sitter trees are substantial, causing avoidable memory pressure and reducing the effectiveness of the LRU policy. Include parsed-tree size (or add a conservative overhead when parsed.is_some()) in entry accounting so eviction tracks true footprint.

// src/apprt/services.rs
let bytes = estimated_text_store_bytes(&source.text).max(1);
...
parsed: Option<Arc<phosphor::ParsedSyntax>>,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant