Skip to content

feat(text): add shaper-verified tabular-digit template fast path for single-line LiveText - #2119

Merged
Hona merged 1 commit into
devfrom
feat/2084-tabular-live-text
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
feat/2084-tabular-live-text

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Refs #2084

Adds an internal, shaper-verified tabular-digit template fast path for single-line ASCII LiveText updates (zero public API changes, no TextLayout enum changes, no vendor/ patches).

How it works

flowchart LR
  A[LiveText change] --> B{Printable ASCII 1..=64B with digit?}
  B -- no --> F[Full reshape: layout_live]
  B -- yes --> C{Cache key: mask + TextStyle + scale}
  C -- 1st seen --> O[Shape & record width: Observed]
  C -- 2nd distinct string --> W{full_width bits equal?}
  W -- no --> I[Mark Ineligible, 0 probes]
  W -- yes --> V[Verify: 10 uniform fills + 102B De Bruijn + GSUB/GPOS/kern/GDEF/AAT]
  V -- pass --> T[Verified Rc<TabularTemplate>]
  V -- fail --> I
  C -- Verified hit --> S[Swap digit glyph IDs in place, bump value_id]
  S --> P[Paint: glyphs_for_tabular + fold value_id into text_quads key]
Loading
  • Exactness proof (crates/rune-text/src/layout/tabular.rs, crates/rune-text/src/layout/tabular/tables.rs):
    • Shapes all 10 uniform fills ('0'..='9') and asserts bit-identical full_width, width, height, all 12 LineMetrics fields, run metadata, 1-to-1 LTR cluster ranges/advances/word boundaries, non-digit glyphs/positions, and digit positions/advances.
    • When adjacent digit slots exist, shapes a 102-byte order-2 De Bruijn sequence covering all 100 ordered digit pairs strictly interior to prove zero digit-pair kerning or ligatures.
    • Inspects active GSUB/GPOS/GDEF/kern tables via skrifa::raw (rejecting AAT morx/mort/kerx, multi-glyph ligatures overlapping digit slots such as 1/2 under frac/dlig, and asymmetric contextual rules; allowing digit-symmetric rules like Inter's calt colon/hyphen shift).
    • Bounded cache (256 masks / 2 MiB LRU), cleared in TextSystem::drop_shaped().
  • Runtime integration (crates/rune/src/runtime/):
    • Keeps TextLayout::Single(template_layout) in node.text_layout and stores Option<Rc<TabularGlyphs>> on NodeCold::tabular_layout (updated in place via Rc::get_mut for zero per-tick allocation).
    • Carries tabular_layout alongside text_layout across memo reuse, relayout, and virtual remount; clears it whenever layout leaves the tabular path.
    • Emits via TextSystem::glyphs_for_tabular in paint/content.rs, paint/text_flights.rs, and motion/flights.rs, folding TabularGlyphs::value_id() into PaintState::text_quads.

Benchmark (--profile perf, 9 paired alternating runs, 500 changed "000.00 bar" values/tick × 60 ticks, scale 2.0, headless CPU; excludes GPU upload/presentation)

Font / style Metric Before (layout_live) After (layout_live_tabular_into) Ratio
Inter 12 pt 'tnum' 1 Shapes / 500-cell tick 500 0 —
Inter 12 pt 'tnum' 1 Update median (min–max) 7,620 ns/val (6,209–9,253) 71.5 ns/val (54.8–108.5) 106.6×
Inter 12 pt 'tnum' 1 Update + quad emit median 8,931 ns/val (7,210–10,904) 666 ns/val (521–787) 13.4×
Inter 12 pt 'tnum' 1 500-cell tick (update / total) 3.81 ms / 4.47 ms 0.036 ms / 0.333 ms —
IBM Plex Mono 12 pt Shapes / 500-cell tick 500 0 —
IBM Plex Mono 12 pt Update median (min–max) 4,470 ns/val (4,255–5,155) 70.3 ns/val (57.6–112.3) 63.6×
IBM Plex Mono 12 pt Update + quad emit median 5,512 ns/val (5,115–6,256) 666 ns/val (537–709) 8.3×
IBM Plex Mono 12 pt 500-cell tick (update / total) 2.24 ms / 2.76 ms 0.035 ms / 0.333 ms —

Verification

  • Differential proof suite (crates/rune-text/src/layout/tabular/tests.rs): bit-exact glyph IDs, positions, GlyphQuads (origin, zoom, glide, band, bytes), line box, caret geometry, hit testing, and selection rects across Inter Regular/Medium/SemiBold, IBM Plex Mono, proportional fallback, frac/dlig/ordn, RTL, control chars, and synthetic adversarial fonts (hidden pair kern, 3-digit ligature, separator ligature).
  • End-to-end headless Runtime tests (crates/rune/src/runtime/motion/tabular_live_text_tests.rs, memo_reuse_live_text_tests.rs): 500-cell grid, memo reuse across commits, paint-keep and text_quads invalidation, selectable a11y TextRun parity, and font switching.
  • Verified on Windows (rune-text, rune, doctests, clippy, check-wasm, check-webgl), macOS arm64 (rune-text and rune tabular tests), and Linux aarch64 (cargo check -p rune -p rune-kit --tests). Not run: live GPU window presentation.

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