Skip to content

#3929: pre-compile before a fork only for scans of 500+ files (small scans keep #3923's 30% win) - #3939

Merged
squid-protocol merged 2 commits into
mainfrom
claude/fork-precompile-gate
Sep 27, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
claude/fork-precompile-gate

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Closes #3929. This is the last commit of the #3929 work. #3931 was squash-merged at 093be90a, one commit before this one.

#3931 made the parent process compile, before forking the pool, the rules of every language that claims one of the scan's extensions. That fixed the regression on large scans. But the same A/B showed it losing #3923's gain on small scans.

A small scan's workers start on idle cores. There, compiling lazily wins:

  • in parallel;
  • only the languages each worker meets. On this 40-file C set, the workers never need objective-c.

One serial compile of every claimant in the parent is slower. Large scans keep every core busy to the end, so there a worker's own compile adds to wall time and compiling once in the parent wins.

This PR gates the pre-fork compile on total_files >= 500 (_PRECOMPILE_MIN_FILES). It is a 10-line change to galaxyscope.py.

Measured

tests/tools/phase_ab.py on a 4-core Linux box: alternating rounds, an A-vs-A control, and GITGALAXY_LICENSE_KEY set.

The process column is the whole command, the import included. #3931 added it because wall (PIPELINE_SUCCESS) starts after the import. #3923 moved about 2 s of rule compilation out of the import and into the scan, so wall charges that work to #3923 while the baseline's same work sits before its clock starts.

40 C files (language-crucible/data/c, 5 rounds), all relative to pre-#3923 main:

engine process wall
A-vs-A control +0.7% +0.4%
main with #3923 −29.6% +4.6%
#3931, ungated (earlier run) −21.3% +18.9%
this PR −30.4% +2.6%

3,280 files (language-crucible/data, all 66 languages, 3 rounds):

engine process wall
A-vs-A control −0.1% +0.1%
main with #3923 +0.1% +2.4%
this PR +0.0% +3.0%

Type of change

  • Bug fix
  • New feature / language support
  • Parsing or engine logic
  • Docs, tooling, or CI only
  • Other

The change affects scheduling only, not output. Rules compile at a different moment, which cannot change what they match, and the artifact-identity check above confirms it.

CI checklist

Differential Scan target

n/a

Verification

$ PYTHONPATH=... python tests/tools/phase_ab.py --repo ../language-crucible/data/c --rounds 5 --control \
    --engine pre3923=<c69bea35> --engine main=<6b040ee0> --engine fix=<this branch>
$ ... same, --repo ../language-crucible/data --rounds 3

A compile trace shows where compilation lands:

  • On the crucible corpus with pre-compile on, forked workers compile 0.012 s in total (lazy: 0.5 s).
  • On the 40-file set, each worker compiles only c (about 0.16 s, in parallel) and never objective-c.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X9PBcL8evG7CEzff1zE8v5


Generated by Claude Code

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
@squid-protocol squid-protocol added this to the Yes, but can it go faster...? milestone Sep 27, 2026 — with Claude
@squid-protocol squid-protocol added core-engine Modifications to the central physics and parsing engine performance labels Sep 27, 2026 — with Claude
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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

Copy link
Copy Markdown
Owner Author

macOS 3.9 failure: test_agc_assembly_func_start_redos_immunity. Caused by #3923, not by this PR's change. Fixed in 30670abb.

  • What happens. assert_redos_immune spawns a child and gives it 1 s from start(). Since #3914: compile the language registry's rules on first use, not at import #3923, a registry rule is a LazyPattern, and unpickling one runs gitgalaxy's language registry. The child imported 74 gitgalaxy modules (258 ms on an idle box, more on a loaded runner) inside that window, so a linear rule was reported as hung.
  • The fix. _plain() compiles the rule in the parent. A plain pattern unpickles through re alone: 0.6 ms and no gitgalaxy import.
    • _best_of_timing now also compiles before its clock starts.
    • Disabled rules (None) pass through as before.
  • Where. Applied in both harnesses and in livecode's scaling helper.
  • Verified. tests/extraction: 8,922 passed.

Generated by Claude Code

@squid-protocol
squid-protocol merged commit 6b604f9 into main Sep 27, 2026
34 of 40 checks passed
@squid-protocol
squid-protocol deleted the claude/fork-precompile-gate branch September 27, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy rule compilation (#3923) makes Linux scans ~9% slower: forked workers each recompile the rules

2 participants