input: one compiled link regex per pattern for the whole process
Merged
LA
3d ago+222+222+012345678901234567890123456789-7-7-0123456789
Summary
- Each new surface compiled every configured link regex twice on the main thread: once for the surface (
Surface.DerivedConfig.init) and once for its renderer (renderer/link.zigSet.fromConfig). In a cmux workspace switch trace (Time Profiler, 6 switches, cmux run 20261103T031956Z-ed80d47d) that was 6.3 ms ofonig_compileper switch, about 0.5 ms per compile of the default URL regex. - New
src/input/link_regex.zig: one compiled regex for each pattern in the process, counted by its users. Surfaces and renderer link sets acquire on init and release on deinit. Up to 16 unused patterns stay compiled, so a switch that frees surfaces and then makes new ones compiles nothing. Matching does not change (same options asinput.Link.oniRegex). - Thread safety: Oniguruma 6.9.9
onig_searchnever writes to aregex_t(noreg->assignment inregexec.c; the last search-time write,int_map_backward, was removed "for thread-safe", HISTORY 2016/07/17). Only compile and free change aregex_t, and both happen under the cache lock. - Base:
release/cmux-9ce9b7d0-e2(cmux's pin34e73ba8b), so cmux can pin it without the v1.4.0 / Zig 0.17 merge onmain. A port tomainis a follow-up.
Testing
- Red (test commit
5410e5d44, run 41574025483 on scratch branchscratch/tcc-link-regex-red, which only narrows the test filters): 2 of 2 new tests fail ("expected struct_re_pattern_buffer@...030, found ...230"); 82 other tests pass. - Green (fix
dfd07de4a, run 41574028017 onscratch/tcc-link-regex-green, which adds the new filters to the full patch filter list): ghostty-test 222/222, lib-vt 475/475, build, no-gettext and link smoke pass. - The workflow's test filter list is not changed in this PR (no new CI test step). The scratch branches are never merged.
Changelog
none
![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
Shares one compiled link regex per configured pattern across all surfaces and renderers, so a new surface no longer compiles each regex twice on the main thread (about 0.5 ms per URL regex compile, 6.3 ms of onig_compile per workspace switch in cmux's trace).
- Adds
src/input/link_regex.zig: a process-wide cache of compiled regexes, reference-counted by surfaces and renderer link sets (acquire on init, release on deinit). - Patterns unused for a while stay compiled (up to 16), so a workspace switch that frees surfaces and creates new ones compiles nothing.
- Sharing is safe across threads: Oniguruma 6.9.9 search never writes to a
regex_t; only compile and free mutate it, and both happen under the cache lock. Matching behavior is unchanged. - Bases off
release/cmux-9ce9b7d0-e2so cmux can pin it without the v1.4.0 / Zig 0.17 merge; porting tomainis a follow-up.