Skip to content

perf: cut Optical Detector regex cost (COBOL Cartography is 76s CPU / 55% of extraction) #3182

Description

@squid-protocol

Context / baseline

#3175 (largest-first worker dispatch, PR #3181) shipped output-safe but wall-flat — scheduling was never the bottleneck. A full profiled scan of all_language_repo (16.53s wall, 1.22M LOC, 73.8k LOC/s) located the real limiters. This issue covers limiter #1: the Optical Detector regex phase. Sibling: the single-threaded tail (see companion issue).

Cumulative per-worker CPU by extraction phase (÷~16 cores):

Phase CPU (Σ workers) ms/file
5_Optical_Detector 76.0s 26.5
5.5_Security_Lens 36.1s 12.6
4_Lexical_Scan 7.4s 2.6
others (lang detect / import regex / token / aperture / disk) ~5s —

Optical Detector is 55% of all per-file work — 2× the already-gated Security Lens. And it's composition-driven, not size-driven: 26.5 ms/file on ALR vs ~10.6 ms/file on curl, because ALR contains COBOL. The --splicing-speed tail is unambiguous:

2.68s  cobol::Cartography_Mode_A_Labels   ← single most expensive regex in the whole scan
1.60s  cobol::func_start
1.44s  typescript::Cartography_Mode_B_Braces
0.78s  cobol::safety
0.66s  cobol::fragile_debt
... 7 of the top ~15 modes are cobol::

Goal

Bring Optical Detector cumulative CPU down the way #3069 / #3072 / #3173 brought down Security Lens, starting with the hottest modes.

Seam / files

Plan

  1. Profile-confirm the hot modes per language (COBOL Cartography_Mode_A_Labels, func_start; TS Cartography_Mode_B_Braces) via --splicing-speed on ALR and a COBOL-heavy repo.
  2. Per hot mode, run pattern_is_line_local: if line-local, opt it into _line_gates and attach build_line_gate (the perf: per-line gating for the line-anchored rules the literal prefilter can't touch #3072 path); if not line-local but literal-anchorable, attach derive_literal_gate(prefer_selective=True) (the perf: Security_Lens is ~30% of scan CPU and completely ungated — prefilter + de-double-sweep (est. ~10% end-to-end) #3173 path).
  3. For modes that resist gating (note: func_start was previously found "unwinnable"), evaluate regex rewrite / anchoring / removing catastrophic alternations, or a cheap pre-scan literal reject.
  4. Correctness guard: a registry property test (mirror tests/.../test_line_gates.py) proving the gated finditer returns the identical match set as ungated for every opted-in rule.

Checklist

  • --splicing-speed tail captured for ALR + a COBOL-heavy repo; hot modes ranked.
  • pattern_is_line_local verdict recorded per hot mode.
  • COBOL Cartography_Mode_A_Labels gated (line or literal) OR rewrite justified.
  • COBOL func_start re-evaluated (prior "unwinnable" — confirm or beat).
  • TS Cartography_Mode_B_Braces gated/optimized.
  • Property test proves identical match sets for every newly gated rule.
  • A/B (phase_ab.py --rounds 3 --control, curl + ALR) shows Optical Detector CPU ↓ with audit.json + sarif.json byte-identical.
  • Golden crucible green both legs.

Verification methodology

tests/tools/phase_ab.py --repo <repo> --rounds 3 --control --engine main=<origin/main> --engine mine=<change> on curl + all_language_repo. Env: GITGALAXY_LICENSE_KEY=COMMUNITY_FREE_TIER, PYTHONPATH, KEYWORD_ROSETTA_PATH + LANGUAGE_CRUCIBLE_PATH, Bash sandbox OFF, v6/.venv python. The harness proves audit/sarif identity; the A-vs-A control separates real deltas from hash-seed noise. Judge cumulative per-worker CPU (--file-speed chart), not wall.

Lineage: builds on the prefilter/gate work in #3069 / #3072 / #3173; baseline established alongside #3175 / #3181.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature, sensor, or structural signatureperformancepriority: highCore feature broken, but workarounds exist

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions