Skip to content

perf(runtime): accelerate editor and plugin hot paths - #309

Merged
fcoury-oai merged 81 commits into
mainfrom
fcoury/performance-optimization
Aug 22, 2026
Merged

fcoury-oai merged 81 commits into
mainfrom
fcoury/performance-optimization

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

Common Red interactions repeatedly traversed entire documents, rebuilt unchanged syntax and layout state, refreshed plugins and Git data unnecessarily, and copied values across plugin and language-service boundaries. Those costs compounded during typing, Vim editing, search, completion, workspace navigation, and startup.

What changed

  • Index document positions, Vim motions/operators, Unicode display coordinates, wrapped text, undo restoration, and embedded text-area edits while preserving grapheme, CRLF, and editor/TextArea parity.
  • Reuse bounded syntax captures, layout geometry, picker/search results, and Git/workspace state; preserve custom queries, reserved identifiers, nested Markdown languages, and offscreen fenced-code context.
  • Reduce rendering, completion, LSP synchronization, plugin startup/event delivery, Husk analysis/runtime, Agent transcript, inline-assistance, Neo-tree, preferences, and crash-recovery restoration work.
  • Add release-mode hotspot fixtures, before/after comparison tooling, real-terminal PTY coverage, focused regression tests, and a source-backed roadmap covering 33 runtime areas.

Measured results

docs/performance-optimization-2026-08-21.md records 417 independently measured runtime paths that improved by at least 50%, using frozen release baselines, alternating samples, and actual-terminal measurements where applicable. The median improvement is 90.56%; 213 paths improved by at least 90%, and 182 results come from real-terminal PTY sessions. Examples include:

  • PowerShell variable highlighting: 99.04% faster; fenced PowerShell variables: 99.15% faster.
  • Actual-terminal PowerShell highlighting: 94.55% faster; corresponding complete edit frames: 70.57% faster.
  • Deep, offscreen fenced PowerShell highlighting: 89.97% faster; corresponding edit frames: 68.89% faster.
  • Multi-file startup loading: 98.92% faster; actual-terminal bundled-plugin startup: 51.88% faster.
  • Actual-terminal incremental search query resolution: 99.74% faster; crash-recovery buffer restoration: 99.77% faster.

Single-file process startup, terminal diff/flush, durable recovery snapshot writes, some complete event paths, and platform-specific paths have not reached the 50% target and are explicitly tracked as follow-up work.

How to Test

  1. Build the optimized editor and hotspot fixture:

    cargo build --locked --release --bin red --example performance_hotspots
    target/release/red --self-check

    Expect every bundled plugin to activate and red self-check ok.

  2. Exercise real-terminal typing, incremental search, and file-picker latency:

    python3 scripts/interaction_bench.py --binary target/release/red typing
    python3 scripts/interaction_bench.py --binary target/release/red search --query self
    python3 scripts/interaction_bench.py --binary target/release/red picker --query src/editor.rs

    Expect successful PTY sessions with populated event, highlighting, and rendering timing tables.

  3. Check the offscreen Markdown fence regression and Unicode/CRLF rope boundaries:

    cargo test --locked --lib markdown_viewport_preserves_offscreen_fenced_language_after_edit -- --test-threads=1
    cargo test --locked --lib markdown_fence_lookback_stops_at_closing_markers_and_bounds_deep_documents -- --test-threads=1
    cargo test --locked --lib line_ranges_preserve_exact_line_endings_and_final_line -- --test-threads=1

    Expect all focused tests to pass, including nested-language highlighting after the fence opener scrolls offscreen and exact Unicode/CRLF boundary handling.

  4. Run the existing plugin callback performance gate:

    cargo run --locked --release --example husk_cursor_bench -- --assert

    Expect the benchmark assertions to pass.

Full validation passed: cargo clippy --locked --all-targets --all-features -- -D warnings, cargo test --locked --all-targets --all-features -- --test-threads=1 (2,302 unit tests passed, 2 ignored, plus every integration/example target), and cargo fmt --all -- --check.

@fcoury-oai
fcoury-oai merged commit 2518f3f into main Aug 22, 2026
13 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/performance-optimization branch August 22, 2026 16:51
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