Skip to content

Reuse in-flight line highlighting and stop canceled queries - #462

Merged
simonbs merged 2 commits into
mainfrom
codex/reuse-highlight-requests
Oct 27, 2026
Merged

simonbs merged 2 commits into
mainfrom
codex/reuse-highlight-requests

Conversation

@simonbs

@simonbs simonbs commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Repeated line preparation could cancel and restart equivalent highlighting, while canceled Tree-sitter queries continued collecting matches. Keep one pending request for unchanged line input, cancel it on invalidation/removal/offscreen transitions, and reject obsolete operation/input identities before applying styles鈥攊ncluding after client theme callbacks.

Background captures now own copied trees and share frozen predicate text per generation, so editing cannot mutate their inputs. Query iteration cooperatively stops between matches/captures. Synchronous destination preparation still applies styles before measurement; it now also refreshes visible fragments when revealing an already-visible destination leaves the scroll offset unchanged. The fresh-editor rendering oracle reproduced that redraw bug on the predecessor before verifying the fix.

Evidence

Compared Release builds against df9b56fd94131c0f60477613dda8f29e7f0aabe7 on the same dedicated iPhone 17 Pro / iOS 27.2 simulator. For five synthetic cancellation trials, median remaining worker time after canceling an executing dense 60 KB JSON query fell from 40.326 ms to 0.141 ms; the 600 KB stress case fell from 670.783 ms to 0.072 ms. Whole-process CPU measurements showed the same bounded benefit.

No steady-scroll speedup is demonstrated. Two ordinary-scroll runs per version separated loading, first traversal, reversals, cached revisits, and horizontal scrolling. Sampled steady traversal canceled no requests in either version; initial unwrapped layout starts/cancellations fell from 32/16 to 17/1. Callback stalls and CPU varied. Frozen predicate text adds a document-sized UTF-16 snapshot (about 50 MiB for this local fixture). Full measurements, methodology, and limits are in HighlightingPerformance.md.

Validation

  • Ran the 302-test Release unit suite: 301 passed; the new rendering oracle exposed the pre-existing no-op destination redraw bug. After fixing it, all 22 affected tests passed. Test-file lint cleanup then passed its 13-test affected rerun; unaffected passing results were reused.
  • Regressions cover reuse, cancel/revisit, stale queued callbacks, reentrant theme cancellation, tree/text snapshot lifetime, query cancellation, destination geometry, and a fresh-editor geometry/rendering oracle after wrapped/unwrapped Unicode/bidi/tab editing, split/join, multiline replacement, undo/redo, syntax changes, EOF deletion, and theme/document replacement.
  • Release Example builds, changed production-file SwiftLint, and diff whitespace checks pass.
  • Local gesture captures exercised slow drags, flings, reversals, horizontal scrolling, and wrapped EOF/reverse scrolling. Sampled frames showed no blank viewports, missing bands, obvious jumps, or color loss. Fixtures, recordings, logs, and temporary instrumentation remain local.

Physical-device performance, compositor hitch traces, and long wrapped-line marked-text composition during pending work remain unverified. Display-link delays are main-run-loop stall proxies, not compositor frame guarantees. No phone app or primary checkout sources were changed. Stage 1 only; no appearance-only rewrapping, chunked highlighting, or memory eviction.

@simonbs
simonbs merged commit 2f08c83 into main Oct 27, 2026
9 checks passed
@simonbs
simonbs deleted the codex/reuse-highlight-requests branch October 27, 2026 12:50
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