Skip to content

perf(render): speed up write-streaming previews and harden edge cases#136

Merged
dnouri merged 1 commit intomasterfrom
perf/write-streaming-fontify
Feb 22, 2026
Merged

perf(render): speed up write-streaming previews and harden edge cases#136
dnouri merged 1 commit intomasterfrom
perf/write-streaming-fontify

Conversation

@dnouri
Copy link
Copy Markdown
Owner

@dnouri dnouri commented Feb 22, 2026

Summary

This PR improves performance and correctness of streaming previews for write tool calls in the chat render path.

The core change is to avoid expensive redraw work when a delta only extends the trailing partial line (which does not affect the visible complete-line tail), while still keeping the fontify buffer synchronized.

What changed

  • optimized pi-coding-agent--display-tool-streaming-text hot path:
    • keep fontify buffer synced on every delta
    • skip tail extraction + overlay redraw when only trailing partial line changed
  • initialized fontify mode once per per-language buffer via pi-coding-agent--fontify-initialize-buffer-mode
  • extracted overlay body rewrite into pi-coding-agent--tool-streaming-replace-overlay-body
  • hardened preview edge cases:
    • empty-content updates clear stale preview text
    • same-size rewrites refresh correctly
    • same-size unchanged updates skip churn
    • shrinking-content anomaly path stays correct
  • made visual-line truncation consistent for language-aware streaming tails while preserving syntax properties
  • added regression tests focused on touched paths and edge behavior

Why

Large write streams were paying too much per-delta work and had edge cases where preview state could become stale or inconsistent (especially around empty or rewritten content).

User impact

  • smoother streaming for large write tool calls
  • more stable, predictable preview behavior under provider delta quirks
  • no user-facing command/API changes

Validation

Standard gates

  • make check (639/639)
  • make test-integration (17/17)
  • make test-gui (13/13)

Additional perf/regression campaign

Executed tmp/TODO-perf-issues-test-plan.md end-to-end (TP-01..TP-36), including:

  • tmux + emacs -nw targeted and full unit runs
  • multi-session isolation checks
  • abort/restart lifecycle checks
  • UI boundary checks (resize, scrolling, collapse/expand, visit-file mapping)
  • protocol anomaly checks (duplicate deltas, shrinking content, mode-init failure injection)
  • live RPC stress/soak runs with summary and function-stat analysis

All TP steps passed with evidence recorded in the plan file.


Note: the line
pi-coding-agent: fontify mode init error for python: (error "boom")
seen in some test logs is expected from intentional failure-path tests.

Optimize write-tool streaming updates while hardening edge cases and improving test signal-to-noise.

- keep per-language fontify buffers in sync, initialize mode once, and skip expensive tail extraction/redraw when only trailing partial-line text changes
- centralize pending-tool overlay body replacement and apply visual-line/byte capping consistently for raw and language-aware tails
- handle empty/same-size rewrites plus zero-limit edge cases safely (zero max-lines, zero width, zero-line tail requests)
- add regressions for partial-line fast paths, fallback behavior, preview bounds, and edge-case truncation/tail semantics
- make === Unit Tests ===
Ran 644 tests, 644 results as expected, 0 unexpected (2026-02-22 14:23:15+0100, 23.904274 sec) terse on green runs while preserving full diagnostics on failures; add  for full ERT output
- update AGENTS test guidance and adjust tests to capture/assert expected minibuffer messages instead of leaking log noise
@dnouri dnouri force-pushed the perf/write-streaming-fontify branch from e41d1a0 to 00b13c3 Compare February 22, 2026 13:23
@dnouri dnouri merged commit c0a037d into master Feb 22, 2026
7 checks passed
@dnouri dnouri deleted the perf/write-streaming-fontify branch February 22, 2026 13:37
dnouri added a commit that referenced this pull request Feb 25, 2026
Optimize write-tool streaming updates while hardening edge cases and improving test signal-to-noise.

- keep per-language fontify buffers in sync, initialize mode once, and skip expensive tail extraction/redraw when only trailing partial-line text changes
- centralize pending-tool overlay body replacement and apply visual-line/byte capping consistently for raw and language-aware tails
- handle empty/same-size rewrites plus zero-limit edge cases safely (zero max-lines, zero width, zero-line tail requests)
- add regressions for partial-line fast paths, fallback behavior, preview bounds, and edge-case truncation/tail semantics
- make === Unit Tests ===
Ran 644 tests, 644 results as expected, 0 unexpected (2026-02-22 14:23:15+0100, 23.904274 sec) terse on green runs while preserving full diagnostics on failures; add  for full ERT output
- update AGENTS test guidance and adjust tests to capture/assert expected minibuffer messages instead of leaking log noise
dnouri added a commit that referenced this pull request Feb 26, 2026
Optimize write-tool streaming updates while hardening edge cases and improving test signal-to-noise.

- keep per-language fontify buffers in sync, initialize mode once, and skip expensive tail extraction/redraw when only trailing partial-line text changes
- centralize pending-tool overlay body replacement and apply visual-line/byte capping consistently for raw and language-aware tails
- handle empty/same-size rewrites plus zero-limit edge cases safely (zero max-lines, zero width, zero-line tail requests)
- add regressions for partial-line fast paths, fallback behavior, preview bounds, and edge-case truncation/tail semantics
- make === Unit Tests ===
Ran 644 tests, 644 results as expected, 0 unexpected (2026-02-22 14:23:15+0100, 23.904274 sec) terse on green runs while preserving full diagnostics on failures; add  for full ERT output
- update AGENTS test guidance and adjust tests to capture/assert expected minibuffer messages instead of leaking log noise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant