Repository navigation
input: one compiled link regex per pattern for the whole process - #69
Conversation
Every new surface compiled each configured link regex twice on the main thread (Surface DerivedConfig and the renderer link.Set). In cmux's workspace switch trace this was 6.3 ms of onig_compile per switch (about 0.5 ms per new surface). These tests fail until the compiled regexes are shared.
Every new surface compiled each configured link regex twice on the main thread: once for the surface (DerivedConfig) and once for its renderer (link.Set). With the default URL regex that is about 0.5 ms per compile; cmux's workspace switch trace showed 6.3 ms of onig_compile per switch. input/link_regex.zig keeps one compiled regex per pattern, counted by its users (surfaces and renderer link sets acquire on init, release on deinit). 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, so one regex serves the app and renderer threads of every surface. Matching is unchanged.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Review (independent review subagent): SHIP at dfd07de Reviewed The oniguruma 6.9.9 Release Nits: a partial failure in the acquire loops leaks earlier refs (an existing pattern, harmless). The |
Summary
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.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).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.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
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.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.Changelog
none
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith 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_compileper workspace switch in cmux's trace).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).regex_t; only compile and free mutate it, and both happen under the cache lock. Matching behavior is unchanged.release/cmux-9ce9b7d0-e2so cmux can pin it without the v1.4.0 / Zig 0.17 merge; porting tomainis a follow-up.Written for commit dfd07de. Summary will update on new commits.