perf(terminal): compile each link regex once per process (ghostty-next dfd07de4a)
WAIT (lead, STATUS 8443): no ready-to-land until PL-ghostty (GhosttyNextKit owner, plans/cmux-next/OWNERS.md) has reviewed the fork change manaflow-ai/ghostty-next dfd07de4a2948f86a0a4d3032200f73ef003e787 (PR #69) and says in STATUS that the push of release/cmux-9ce9b7d0-e2 (34e73ba8b -> dfd07de4a, made by an agent before review) stands, or reverts it. Also waits for the bench (tcc-regex-ab-base/head).
Summary
Each new terminal surface compiled every configured link regex twice on the main thread inside ghostty_surface_new: once for the surface (Surface.DerivedConfig) and once for its renderer (renderer/link.zig Set.fromConfig). In the HEAVY workspace switch trace (STATUS 8158: cmux23, run 20261103T031956Z-ed80d47d, 6 Cmd-digit switches) this was 6.3 ms of onig_compile per switch, about 0.5 ms per compile of the default URL regex. Every new tab, split, reopen and switch that makes a terminal paid it.
This pins ghostty-next dfd07de4a (fork PR manaflow-ai/ghostty-next#69, on release/cmux-9ce9b7d0-e2 = the current pin 34e73ba8b plus only that PR). Its new src/input/link_regex.zig keeps one compiled regex per pattern in the process, counted by its users: surfaces and renderer link sets acquire it on init and release it on deinit, and up to 16 unused patterns stay compiled, so a switch that frees surfaces and makes new ones compiles nothing. Oniguruma 6.9.9 search never writes to a regex_t (no reg-> assignment in regexec.c; HISTORY 2016/07/17 removed the last search-time write "for thread-safe"), so the app and renderer threads of every surface share one regex. Matching does not change.
The commit moves the URL and checksum together (GhosttyNextKit xcframework-dfd07de4a2948f86a0a4d3032200f73ef003e787-apple-v6, sha256 a04d2fc3... from its SHA256SUMS), and the ghostty-next gitlink, the notices and docs/ghostty-fork.md (with conflict notes) with it.
Testing
Red and green are Zig tests in the fork, run by the fork's GhosttyNextKit workflow on a macOS runner (never on a developer Mac). The workflow's filter list is not changed by the fork PR; scratch branches scratch/tcc-link-regex-red and scratch/tcc-link-regex-green (never merged) added the filters for these runs.
- Red: run 41574025483 at test commit
5410e5d44: 2 of 2 new tests fail ("expected struct_re_pattern_buffer@...030, found ...230": two surfaces and a renderer get different compiled regexes); 82 others pass. - Green: run 41574028017 at
dfd07de4a: ghostty-test 222/222 (all patch filters plus the new ones), lib-vt 475/475, build, no-gettext and link smoke pass. - Release: run 41575301068 published the pinned kit.
- App compile on the fleet: compile-check job c84b6afb79f5dd68adb88de4 (result in a PR comment).
Observed / Not run
- Observed: the fork red and green runs above; the published release and its SHA256SUMS.
- Not run yet: the before/after bench (scripts/measure/instant-new-surfaces.sh, split_right and new_terminal, warm, idle, 20 runs, bench config) on cmux24 through the mini scheduler, base 6ee46ce9380 vs this head (specs tcc-regex-ab-base / tcc-regex-ab-head). No ready-to-land before it shows a gain.
- No cmux-side Swift regression test: the sharing is inside libghostty and has no public API to observe it; the fork's Zig tests are the regression tests.
- macOS 14 and 15: not run (no fleet host).
Changelog
Changed: A new terminal, split or tab opens with less main-thread work (each link regex is compiled once, not twice per terminal).
Proof
No capture: no visible change; the gain is main-thread time per new terminal (bench above).
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Pins ghostty-next dfd07de4a, which makes link regexes compile once per process instead of twice per new terminal on the main thread. New tabs, splits, reopens and workspace switches that create a terminal no longer pay ~6.3 ms of onig_compile per HEAVY switch; matching behavior is unchanged.
- Each pattern keeps one compiled regex shared by all surfaces and renderer link sets; up to 16 unused patterns stay compiled, so a switch that frees surfaces and makes new ones compiles nothing.
- Updates the
GhosttyNextKitbinary target URL and checksum, theghostty-nextgitlink, the notices, anddocs/ghostty-fork.mdwith conflict notes.