Expand description
Background overlay worker — static-overlay bucketing off the UI thread.
Phase 5.8.AF.5 / Slice X2.3 (origin); display-line B4.2 (gut + rename).
§Why this exists
Per paramount goal #1 in CLAUDE.md:
Performance. UI thread does no I/O, no parsing, no shaping.
This worker pre-buckets the active document’s static overlay
layers (hlsearch matches, LSP document-highlights, :s///
substitute preview) into per-row quad lists so neither renderer
peer has to walk every overlay range against every visible row
inside its per-frame paint body.
§History (B4.2 gut + rename)
Until display-line slice B4.2 this module was highlights_worker
and carried TWO jobs:
- the span / row prepaint cache (
VisibleSpans/VisibleRows/RowPrepaint, built bybuild_rows/build_rows_with_cache/weave_row) — consumed by the renderers’ shaping path. The cells / display-matrix migration (B-series) severed every read of that cache, so B4.2 deleted it wholesale. - the static-overlay bucket (
bucket_static_overlays) — still consumed every frame by both renderers’ overlay paint paths (TUIrender.rs, GPUIeditor_element.rs). This is the live half and is all that remains here.
The module was renamed overlay_worker because it no longer
produces highlights — only overlay quads.
§Design
- Dispatch’s
publish_render_statepopulatescrate::render_state::SyntaxRenderStateinputs (syntax_handle,scroll,viewport_height,fold_hash,text_version,doc_highlights,static_overlay_version) and firescrate::editor::OverlayWake’sNotify. - The worker
notified().awaits the wake signal.Notifyis permit-style: a burst of publishes wakes the worker exactly once, after which the worker re-reads the latest snapshot. - On wake the worker reads
render_state.load_full().syntax, constructs acrate::render_state::VisibleHighlightsKey, compares it against the key in the currently-publishedcrate::render_state::StaticOverlayQuads, and short-circuits on cache-hit. - On cache-miss with a current snapshot: re-buckets the overlay
layers into per-row quad lists and stores a fresh
StaticOverlayQuadsinto the durablesyntax_static_overlay_quads_cellArc<ArcSwap<…>>. - On cache-miss with a stale snapshot (snapshot’s
text_version< document’stext_version): the worker applies the stale-snapshot HOLD — it stores the new key but preserves the previously-published quads, so a mid-edit window doesn’t recolour overlay backgrounds against pre-edit data.
§Renderer contract
Renderer peers read with:
let rs = editor.render_state.load_full();
let quads = rs.syntax.static_overlay_quads.load();
// quads.quads[i] = per-row RowOverlayQuad list for visible line iEmpty quads is the legal “no overlays yet” state (initial boot,
no overlay layers active, or a pre-first-worker-tick window).
Renderers paint no overlay backgrounds in that case.
Enums§
- Worker
Decision - Recompute decision the worker takes on a wake. Visible for
testing; the production loop calls
recomputedirectly.
Functions§
- recompute
- Pure synchronous recompute. Reads the current published
SyntaxRenderState, decides whether to recompute, and updatesstatic_overlay_quads_cellaccordingly. Returns the decision taken so tests can assert cache-hit / stale-snapshot HOLD / recompute paths without driving the async loop. - run
- Worker entry point spawned at boot. Loops forever, awaiting
the wake
Notify. Each wake re-reads the latestRenderState.syntaxinputs and callsrecompute.