Repository navigation
Description
Summary
#3923 (for #3914) made rule compilation lazy: rules compile on first use, not at import. That took import gitgalaxy.galaxyscope from 3.6 s to 1.6 s, a real win under spawn, which macOS and Windows use by default.
On Linux, though, the scan's worker pool uses fork. Before #3923 the rules were compiled once in the parent and every worker inherited them for free. Now each worker compiles the same rules itself, the first time it meets each language. On a multi-worker scan that costs more than it saves: curl got ~9% slower in wall time.
Measurements
Setup:
- curl (
/nvme-data/gitgalaxy-data/curl, 4,250 files) on a 12-CPU Linux box, Python 3.12. tests/tools/phase_ab.py: alternating rounds, an A-vs-A control, andGITGALAXY_LICENSE_KEY=COMMUNITY_FREE_TIERso the licence delay doesn't count.
1. Before and after #3923 (2 rounds; the A-vs-A control moved wall by −0.7%):
| engine | wall | 3_Language_Detector (CPU) | 5_Optical_Detector (CPU) |
|---|---|---|---|
main before #3923 (c69bea35) |
7.14 s | 2.04 s | 16.35 s |
main with #3923 (34fc2dc9) |
7.78 s | 2.60 s | 16.95 s |
2. Mechanism facts:
multiprocessing.get_start_method()isfork. The pool is a plainProcessPoolExecutor(galaxyscope.py, the Full Suite Gate: Windows at its 30-minute limit, because every tiny test scan spawns worker processes that re-import GitGalaxy #3913 pool block), and there are 12 workers.- Compiling the rules of curl's 15 languages via
detector._compiled_rulescosts 302 ms per process: c 85 ms, cpp 98, perl 55, python 42, the rest under 5 each. - With lazy compilation, each worker pays that the first time it meets each language: up to 12 × ~0.3 s ≈ 3.6 s of repeated CPU.
- Compiling every language's rules takes about 1.5 s (1,208 ms for the other 40), so compiling everything up front is not the fix.
3. Direct test: the same main engine (34fc2dc9), plain versus a driver that compiles curl's 15 languages in the parent before main(). 3 alternating rounds:
| variant | wall per round | mean |
|---|---|---|
| lazy (main as is) | 7.82 / 7.81 / 7.75 | 7.79 s |
| parent-precompiled | 7.31 / 7.33 / 7.32 | 7.32 s (−0.47 s, −6%) |
The precompiled wall includes the parent's ~0.3 s of compiling, and it still recovers most of the 0.64 s regression.
Proposed fix
When the pool's start method is fork, compile in the parent the rules of the languages the Phase-0 census found, right before creating the ProcessPoolExecutor. That means _compiled_rules(LANGUAGE_DEFINITIONS[lang]) for each language in the census or ext tally, plus the embedded languages they pull in.
- It keeps #3914: compile the language registry's rules on first use, not at import #3923's import-time win: nothing is compiled at import, and only the languages the scan uses are compiled.
- It restores free sharing across forked workers.
- It changes nothing under
spawn, where the workers re-import anyway. - The inline path (
_InlineExecutor, small scans) needs no change.
Possible refinement: start that parent compile on a thread during the census, so its ~0.3 s overlaps with I/O.
Acceptance: a phase_ab A/B on curl shows wall back to at or below the pre-#3923 7.14 s. The deterministic surface (audit.json and sarif.json) must be identical, and the golden masters must not move.
Context
The wider gap is separate from this issue. On the same runs, v2.9.1 scans curl in 4.71 s, so current main is +65% and pre-#3923 main is +52%.
- The biggest movers since v2.9.1:
c::Cartography_Mode_B_Braces: 1.73 → 2.63 s;- python
Cartography_Mode_C_Indentation: 0.14 → 1.68 s; 5_Optical_Detector: 12.4 → 16.4 s.
- In-process profiling points at
_calculate_block_metrics: tiktoken encoding became ~6× costlier per call after the Epic: Refactorcalls_out_toextraction to support non-C language paradigms #3264 per-language call-extraction rewrite. - Worth its own bisect.
🤖 Generated with Claude Code
Activity
#3929: compile every claimant of the scan's extensions before a fork
Claude/fork precompile (#3931)
squid-protocol commentedon Sep 27, 2026
Results. The fix is #3931, merged, plus #3939, open. #3939 closes this issue.
Mechanism, confirmed. A compile trace logged every lazy compile by process during a real crucible scan:
.hwith every claimant's rules, so every worker meets objective-c.The metric.
phase_ab'swallexcludes the import, and #3923 moved about 2 s of compiling out of the import into that window. #3931 addsprocess, the whole command. Some of the 9% was that shift, not extra work.Three-way A/B, final state. This was a 4-core Linux box, so the pool had 3 workers. Each figure is the whole-command time against pre-#3923 main, with an A-vs-A control:
audit.jsonandsarif.jsonare IDENTICAL for every engine on both targets.Not measured here: curl. It isn't on this box, and with only 3 workers the dedup win is small. The large-scan benefit rests on your own 12-worker curl result: −0.47 s with a parent pre-compile. The 500-file threshold sits between the measured points: 40 files (lazy is better), 3,280 (neutral to better), and curl's 4,250 (better).
Still open, as you noted: curl is +65% against v2.9.1, from
c::Cartography_Mode_B_Braces, pythonMode_C_Indentationand tiktoken in_calculate_block_metrics. That wants its own bisect.Generated by Claude Code
#3929: pre-compile before a fork only for scans of 500+ files (small …