Repository navigation
perf(detector): Slice 2 — single-pass fused regex closes Pro vs OpenCore regression (0.574x → 1.20x) - #235
Closed
cursor[bot] wants to merge 3 commits into
Closed
perf(detector): Slice 2 — single-pass fused regex closes Pro vs OpenCore regression (0.574x → 1.20x)#235cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
Close the Pro-vs-OpenCore regression captured by the 200k A/B benchmark (speedup_vs_opencore = 0.574 in Slice 1 -> ~1.20 in Slice 2 on the same synthetic seed and runner) without changing the finding contract. Three concrete bottlenecks were addressed: 1. core/prefilter.py: fuse CPF and e-mail patterns into a single compiled alternation (_OPENCORE_CANDIDATE_RX). The hot loop now binds .search to a local attribute and uses a list comprehension. Original _CPF_CANDIDATE_RX and _EMAIL_CANDIDATE_RX symbols stay exported for backward-compat with downstream importers and tests. 2. pro/worker_logic.py: rewrite basic_python_scan as a SINGLE pass per row using a fused alternation _FUSED_PRO_RX with named groups (cpf | email | card). CPF and e-mail short-circuit on the first match; Luhn arithmetic only fires when the regex actually matches a card-shape span. Defensive finditer fallback handles rows that carry an invalid card plus a valid CPF / e-mail later in the string, so detection coverage is unchanged. 3. pro/engine.py: process_chunk_worker no longer routes through the no-op deep_ml_analysis hop on the hot path. The helper stays defined for backward import compatibility. Defensive posture (see docs/ops/inspirations/DEFENSIVE_SCANNING_MANIFESTO.md): the refactor only touches in-memory pre-filter code -- no SQL composition, no connection, no lock acquisition. Same finding contract; OpenCore <-> Pro hits parity (100,000 == 100,000) preserved. Resilience posture (see docs/ops/inspirations/THE_ART_OF_THE_FALLBACK.md): the Rust -> Python fallback hierarchy is unchanged. The faster Python fallback narrows the gap between the strongest and the weakest path so Pro stays useful even when the boar_fast_filter extension is missing. Co-authored-by: Fabio Tavares Leitão <[email protected]>
…arity The Slice 1 regression guard intentionally pinned the bad direction (test_benchmark_pro_path_is_slower_in_this_profile) so executive copy could not silently flip the sign of the recorded 0.574x ratio. After the Slice 2 refactor in core/prefilter.py and pro/worker_logic.py, the same 200k A/B benchmark records speedup_vs_opencore = 1.197 (Pro faster than OpenCore on the Cloud Agent VM, Python fallback path, rust_worker_path = false). The guard now asserts the doctrinal direction: - test_benchmark_pro_path_is_at_least_as_fast: speedup >= 0.95 (5 percent noise band on slow CI runners). - Findings parity (opencore_hits == pro_hits) and JSON arithmetic (opencore_seconds / pro_seconds approx speedup_vs_opencore) stay non-negotiable. Also fix a publication-truthfulness bug in run_official_bench.py: the artifact previously hardcoded rust_worker_path = True regardless of whether boar_fast_filter was importable. The runner now reads pro.engine.RUST_AVAILABLE and writes the real value, so manifests and executive decks cannot misattribute Python-fallback numbers to the Rust path. Co-authored-by: Fabio Tavares Leitão <[email protected]>
Add an immutable Slice 2 archive snapshot under docs/ops/lab_lessons_learned/LAB_LESSONS_LEARNED_2026_04_27_slice2.md recording: - The three concrete bottlenecks in the Pro Python fallback (double regex pass, two re.search calls per row, no-op deep_ml_analysis hop). - The fused-regex refactor that closed them (Julia Evans-style RCA). - Defensive posture (zero DB locks, same finding contract, hits parity). - Resilience posture (Rust -> Python fallback hierarchy unchanged). - Verified before/after table (200k rows, 8 workers). - The polarity flip on the regression guard. Refresh docs/ops/LAB_LESSONS_LEARNED.md hub with the new latest summary (Pro now faster) and append the new dated archive row. The 2026-04-25 and original 2026-04-27 reading-guide snapshots stay frozen per the archive contract in ADR 0042. Update docs/ops/SPRINT_GREAT_LEAP_POSTMORTEM.md (and pt-BR mirror) to distinguish Slice 1 (frozen 0.574x measurement) from Slice 2 (current 1.197x measurement) and add a short note on the refactor that fixed the regression. Co-authored-by: Fabio Tavares Leitão <[email protected]>
2 of 3 tasks
FabioLeitao
added a commit
that referenced
this pull request
May 3, 2026
Dated audit + workflow doc updates for the Slack ts 1777370978.136399 ask: 'git branch -r' does not fit one screen, delete cursor/sre-* that are 'integradas ou abandonadas', rule 'se nao tem PR aberto, nao tem por que ter branch no origin'. RCA (audit doc): * After 'git fetch --prune origin' at 2026-04-28T10:19Z (main 4bc0861): - total remote refs: 41 - backed by an OPEN PR (gh): 40 of 41 - in keep-list (main): 1 - TRULY orphan (no PR, not in keep): 1 fix-rust-ci-coverage-9061 * The 40 cursor/sre-* branches are NEITHER 'integradas' NOR 'abandonadas' -- they back live OPEN PRs (#235-#289). Deleting them would auto-close the PRs and lose the audit paper trail (FABRICATED_CLAIMS_INDEX.md cross-references). * Real screen-bloat lever is the open-PR backlog, not orphans (PR #273 covers the 'audit-PR swarm' RCA). Doc updates: * BRANCH_AND_DOCKER_CLEANUP.md S3.1 (EN) / S2.1 (pt-BR): point at new lister, reaffirm open-PR rule + qualifier 'sidequest investigativa obvia progredindo'. * sre_audits/README.md: index sync. Doctrine: DEFENSIVE_SCANNING_MANIFESTO S1.3 (no surprise side effects), THE_ART_OF_THE_FALLBACK S2-S3 (monotonic ladder, diagnostic on fall), AGENTS.md Risk posture. No behavior change. Zero impact on database locks. Co-authored-by: Fabio Tavares Leitão <[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.
Description
Slice 2 of the Engineering Doctrine consolidation (driven by the Slack handoff after Slice 1 pinned the
0.574xregression as official benchmark evidence).Result on the same synthetic 200k seed and runner:
opencore_seconds0.2522420.108942pro_seconds0.4394190.091026speedup_vs_opencore(t_open / t_pro)0.574(Pro slower)1.197(Pro faster)opencore_hits100000100000pro_hits100000100000rust_worker_pathtrue(hardcoded — wrong)false(real)Findings parity preserved; zero database / lock impact; the Rust → Python fallback hierarchy is unchanged.
Root cause analysis (Julia Evans-style)
Three concrete bottlenecks in the Pro Python fallback path (verified by
cProfile-equivalent reasoning over the call graph):pro/worker_logic.py::basic_python_scan. The OpenCore CPF/e-mail regex ran over every row, then the card-shape regex ran over every non-matching row to catch Luhn-valid cards. Net effect: ~2x the regex work of OpenCore on the seeded workload — exactly what0.574xreflected (Pro wall-clock ≈1 / 0.574 ≈ 1.74xOpenCore).re.searchcalls per row incore/prefilter.py._looks_sensitiveinvoked the CPF regex and the e-mail regex separately on the hot path.deep_ml_analysishop inpro/engine.py::process_chunk_worker. A no-op pass that materialised a second list and added a function-call dispatch per chunk.Refactor (Gibson / Savage / NASA posture)
core/prefilter.py—_OPENCORE_CANDIDATE_RX = CPF | e-mailas a single compiled alternation; hot loop binds.searchto a local attribute and uses a list comprehension. The original_CPF_CANDIDATE_RXand_EMAIL_CANDIDATE_RXsymbols stay exported for backward compatibility.pro/worker_logic.py—_FUSED_PRO_RX = CPF | e-mail | card-shapewith named groups. CPF and e-mail short-circuit on the first match; Luhn arithmetic only fires when the regex actually matches a card-shape span. A defensivefinditerwalk handles rows that carry both an invalid card-shape and a valid CPF / e-mail later in the string, so detection coverage is unchanged.pro/engine.py—process_chunk_workerno longer routes throughdeep_ml_analysis; the helper stays defined for backward-compat imports.tests/benchmarks/run_official_bench.py—rust_worker_pathis now derived frompro.engine.RUST_AVAILABLEinstead of being hardcodedTrue.tests/test_official_benchmark_200k_evidence.py— old assertion (speedup < 1.0, "Pro slower") was the right Slice 1 pin but would block legitimate progress; new assertionspeedup >= 0.95(5 percent noise band on slow CI) plus untouched findings parity and JSON arithmetic checks.Doctrine alignment
docs/ops/inspirations/DEFENSIVE_SCANNING_MANIFESTO.md— refactor only touches in-memory pre-filter code: no SQL composition, no DB connection, no lock acquisition, no audit shape change. Same finding contract.docs/ops/inspirations/THE_ART_OF_THE_FALLBACK.md— Rust → Python fallback hierarchy preserved. The faster Python fallback narrows the gap between strongest and weakest path, which is the doctrinal goal: whenboar_fast_filteris unavailable in customer environments, Pro stays useful instead of being a regression.rust_worker_pathflag now reflects reality.Type of change
Checklist
tests/test_scripts.pyare pre-existing failures on this Linux Cloud Agent (nopwshinstalled) and unrelated to this PR (verified withgit stashbaseline).ruff checkandruff format --checkpass on the touched files.LAB_LESSONS_LEARNED.mdhub refreshed, new dated archivelab_lessons_learned/LAB_LESSONS_LEARNED_2026_04_27_slice2.mdper ADR 0042 contract,SPRINT_GREAT_LEAP_POSTMORTEM.mdand pt-BR mirror updated.Related
docs/ops/lab_lessons_learned/LAB_LESSONS_LEARNED_2026_04_25.md, reading guidedocs/ops/lab_lessons_learned/LAB_LESSONS_LEARNED_2026_04_27.md.docs/ops/lab_lessons_learned/LAB_LESSONS_LEARNED_2026_04_27_slice2.md.docs/plans/PLAN_ENGINEERING_DOCTRINE_CONSOLIDATION.md.