Repository navigation
#3914: compile the language registry's rules on first use, not at import - #3923
Merged
Merged
Conversation
`import gitgalaxy.galaxyscope` took 3.6 s, 2.3 s of it compiling ~2,200 rules across every language at import -- paid by every scanning process (and, under `spawn`, again by every worker unpickling its config), although a scan uses the rules of the languages it meets. - language_standards/_lazy_re.py: `re` for the language modules, with `compile` returning a LazyPattern -- a duck-typed re.Pattern that keeps .pattern without compiling, compiles on first use (.flags, any match method), pickles as its source, copies as itself, and equals/hashes as the compiled pattern. is_pattern() / materialize() helpers. - the 55 language modules import it as `re` (one line each). - detector: _compiled_rules() compiles a language's rules in place the first time it is read (primary or embedded), so the hot path and its isinstance(p, re.Pattern) checks see real patterns. - tests: registry audits that filtered on isinstance(p, re.Pattern) use is_pattern (they would otherwise skip every rule); new test_lazy_re.py, including a check that every rule of every language still compiles (the fail-fast a broken regex used to get at import). Import: 3.6 s -> 1.6 s; no rule compiled at import. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X9PBcL8evG7CEzff1zE8v5
Contributor
Owner
Author
|
Outcome: a partial win. It caused a regression on Linux, #3929, which is fixed by #3931 and #3939. What held up:
What it broke:
Part of that 9% was the metric, not the engine. The chain:
Generated by Claude Code |
This was referenced Sep 27, 2026
Merged
squid-protocol
pushed a commit
that referenced
this pull request
Sep 27, 2026
assert_redos_immune spawns a child and allows it timeout_sec (1 s) from start(). Since #3923 a registry rule is a LazyPattern, which unpickles through gitgalaxy's language registry: the child imported 74 gitgalaxy modules (258 ms here, more on a loaded runner) inside that window and a linear rule read as hung (macOS 3.9 on #3939: agc_assembly func_start). _plain() compiles the rule in the parent; a plain pattern unpickles through `re` alone (0.6 ms, no gitgalaxy import). _best_of_timing compiles before its clock too. A disabled rule (None) passes through as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X9PBcL8evG7CEzff1zE8v5
3 tasks
squid-protocol
added a commit
that referenced
this pull request
Sep 27, 2026
…scans keep #3923's 30% win) (#3939) * #3929: pre-compile before a fork only for a scan of 500+ files Three-way A/B (pre-#3914 / main / fix, A-vs-A control, whole-command time): pre-compiling every claimant in the parent took the 3,280-file crucible corpus to -0.7% (main +0.2%), but made a 40-file C scan slower than main (-21% vs -26% against pre-#3914): its 3 workers start on idle cores, where compiling lazily -- in parallel, only what each meets (never objective-c there) -- beats one serial compile. Large scans keep every core busy to the end, where a worker's own compile is wall time (#3929: curl -0.47 s). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X9PBcL8evG7CEzff1zE8v5 * #3914: ReDoS harnesses send their child a plain compiled pattern assert_redos_immune spawns a child and allows it timeout_sec (1 s) from start(). Since #3923 a registry rule is a LazyPattern, which unpickles through gitgalaxy's language registry: the child imported 74 gitgalaxy modules (258 ms here, more on a loaded runner) inside that window and a linear rule read as hung (macOS 3.9 on #3939: agc_assembly func_start). _plain() compiles the rule in the parent; a plain pattern unpickles through `re` alone (0.6 ms, no gitgalaxy import). _best_of_timing compiles before its clock too. A disabled rule (None) passes through as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X9PBcL8evG7CEzff1zE8v5 --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
import gitgalaxy.galaxyscopetook 3.6 s, 2.3 s of it compiling ~2,200 rules across every language at import -- paid by every scanning process (and, underspawn, again by every worker unpickling its config), although a scan uses the rules of the languages it meets.refor the language modules, withcompilereturning a LazyPattern -- a duck-typed re.Pattern that keeps .pattern without compiling, compiles on first use (.flags, any match method), pickles as its source, copies as itself, and equals/hashes as the compiled pattern. is_pattern() / materialize() helpers.re(one line each).Import: 3.6 s -> 1.6 s; no rule compiled at import.
Claude-Session: https://claude.ai/code/session_01X9PBcL8evG7CEzff1zE8v5
Description
Core Engine Modification Checklist
If your PR changes the core parsing engine (
language_standards.py,detector.py,prism.py), you MUST complete the following validation gauntlet before merging:crucible_check.pyto verify diffs, and rancrucible_check.py --update --yesif the baseline changed due to intentional parsing improvements.python tests/tools/tri_comparison_chart.py --all --cilocally first. If you intentionally improved precision, regenerate the baseline:python tests/tools/tri_comparison_chart.py --regenerate --languages <lang>.python tests/tools/tree_sitter_accuracy_audit.py --ci --all. If ground truth drifted for valid reasons, regenerated the baseline withpython tests/tools/tree_sitter_accuracy_audit.py --regenerate --lang <lang>.