Skip to content

[CTX-1610] fix(render): close the font index follow-ups - #2736

Merged
Xuepoo merged 3 commits into
mainfrom
ctx-1610/fix-font-index-followups
Oct 27, 2026
Merged

Xuepoo merged 3 commits into
mainfrom
ctx-1610/fix-font-index-followups

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Priority: P2 | Area: render | Labels: fix,P2,area:render | Milestone: v0.1.0 | RFC: OQ-090 | Task: CTX-1610

Summary

Closes the font-index follow-ups from the shaped-default review (#2733). No correctness change for the shipped path; this is churn, robustness, coverage, and measurement.

Churn

  • Over-cap generic alias: discovered aliases are sanitized once before reconcile, so a 70 KB alias compares equal to the cached 256-byte value and a warm start no longer rewrites. Measured: 13.9 µs warm vs 116 µs + 548 B/start before.
  • Truncated cache: reconcile keeps changed = false when every cached face survives, the extras sort past the retained key, and the writer's face/byte caps would discard them. Detection uses the cached body length (exact writer mirror), so a capped cache is read-only. 16,385-face case: 185.7 ms reparse/start remains, but the 29.8 ms + 1.98 MB rewrite is gone.
  • Caps are documented: 16,384 faces / 32 MiB retained; overflow paths are reparsed each start, retained prefix stays read-only, BITTY_FONT_INDEX=0 is the uncapped escape hatch.

Robustness

  • Cache read: metadata pre-filter → O_NONBLOCK open (OpenOptionsExt, per-platform ABI constants, no new crate) → authoritative fstat before reading. The FIFO-swapped-after-metadata case is tested and cannot block. Windows keeps the plain-open + fstat path; Unix targets without the flag are documented.
  • font-index-v1 is removed best-effort after the first successful v2 write.
  • Directory roots are canonicalized and deduped, so a symlinked alias and the real root index each file once (hardlinks/TTCs still distinct).
  • Docs now say: a warm start reads no face bytes; the cold build's bounded reader reads only name/OS/2/post, and unnameable files fall back to fontdb's whole-file loader.

Measurement

  • New scripts/measure-startup.sh: N launches (default 50), nearest-rank p50/p99/mean/max, isolated XDG/HOME tree, warm-index assertion, --cold window, refuses BITTY_FONT_INDEX=0, not CI-gating. Current debug build: cold 792 ms first launch, warm p50 39 ms / p99 62 ms (50 samples).
  • Two private intra-doc links introduced by earlier work are fixed so just doc-check stays green.

Tests

bitty-render 464 (46 font-index module), bitty-runtime --lib 1315, terminal bin 1327 serial, text-stack/shaped suites green; fmt, clippy -D warnings, Windows cross-check, shellcheck/shfmt, markdownlint, just doc-check all clean.

New: generic-warm no-rewrite, 16,385-face cap read-only, byte-cap e2e, device/socket rejection, FIFO-after-metadata, TTC mtime reparse, v1 ignore/remove/reject, symlink dedupe, writer caps.

Closes #2733.

@Xuepoo Xuepoo added this to the v0.1.0 milestone Oct 27, 2026
@Xuepoo Xuepoo added fix Bug fix area:render Area: rendering P2 Priority: medium labels Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c12a77cb-4a6f-4e95-96fd-fcdc8069476a
Commits

Reviewing files that changed from the base of the PR and between e9097c2 and 78e3491.

Files selected for processing: 5
  • crates/bitty-render/README.md
  • crates/bitty-render/src/font_index.rs
  • crates/bitty-render/src/lib.rs
  • scripts/measure-startup.sh
  • tools/perf/startup
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… claims

- font_index/README/lib.rs: the cold build's bounded reader reads only the
  name/OS-2/post tables; a file it cannot name falls back to fontdb's loader,
  which reads the whole file. The outline/layout/variation exclusion is scoped
  to the bounded path.
- writer_stops_before: document the sorted-(path, face_index) precondition and
  guard it with a debug_assert.
- measure-startup.sh: default 50 runs, fail when the cold launch leaves no
  index (warm samples would silently be cold-index), note the >=100-sample
  p99 bar, and point at the real PB-1 anchor (pb-1-cold-startup-time); the
  same stale anchor in tools/perf/startup is fixed too.
- font_index tests: byte-cap end-to-end no-rewrite case near 32 MiB with a
  synthetic cached body, mirroring the face-count cap test.
…tral

reconcile() gated the byte-capped fast path on the appended faces sorting
after every retained face. Path's order is component-based, so on Windows a
drive-prefixed temp path (Component::Prefix) orders before a root-relative
one (Component::RootDir) and the same capped host rewrote its cache. The
byte budget is a total bound, so the decision now depends only on it: a line
it cannot fit would have to displace a retained face, and skipping the write
keeps the cache stable while the displaced face is reparsed like any other
overflow path. Adds a regression test that drives the sorts-before branch
directly, which also reproduces the Windows failure on Linux.
@Xuepoo
Xuepoo force-pushed the ctx-1610/fix-font-index-followups branch from 4c5a322 to 78e3491 Compare October 27, 2026 03:50

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR-2736 REVIEWER VERDICT: APPROVE

Attribution: independent reviewer subagent (Bitty blitz guard tick, 2026-10-27). Verification performed on a scratch clone of head 7198b05; verdict follows.

Verified:

  • discovered.generic.sanitize() runs pre-reconcile; stale-cache warm-start equality restored; no cap regression (font_index.rs:501).
  • Truncated-cache read-only detection mirrors serialize_index cap logic exactly (font_index.rs:827-846); cached_body_len exact.
  • O_NONBLOCK constants correct for Linux/macOS; post-open fstat is the authoritative swap-race rejection; FIFO-swap regression test present.
  • Targeted runs: cargo check -p bitty-terminal -p bitty-runtime clean; cargo test -p bitty-render --lib = 396 passed / 0 failed (incl. 11 new tests).
  • No let-chains, no hardcoded host/env values, English artifacts.
  • CI on head: pending at review time (7 pass / 7 pending / 0 fail); merge gated on full green.

Non-blocking findings (P2, follow-ups):

  1. writer_stops_before sorts-append edge: mid-prefix append fitting under cap can leave an oversized-batch sibling never persisted (documented accepted trade; suggestion: comment only).
  2. Legacy v1 index residue removed only on changed && write ok — cosmetic staleness path.

Head sha at verdict: 7198b05fa420fcb6368d814241b0d2c9140fab42. Rebase/head note: if head moves, CI+approval re-gate.

@Xuepoo
Xuepoo merged commit 10804c5 into main Oct 27, 2026
20 checks passed
@Xuepoo
Xuepoo deleted the ctx-1610/fix-font-index-followups branch October 27, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:render Area: rendering fix Bug fix P2 Priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[render] Font index follow-ups: churn above caps, test gaps, PB-1 harness

1 participant