Repository navigation
perf(cartography): skip provably-no-op per-match work in _slice_by_braces (#3174) - #3179
Merged
Merged
Conversation
…aces (#3174) Profiling #3174 overturned its premise: the brace scan (`_find_balanced_end`) is ~0.5% of the Mode B key -- already C-fast -- and there is no quadratic re-scan. Mode B's cost is diffuse per-match Python plus per-function block metrics. Three output-identical shavings in the per-match loop: - Guard the c/cpp member-initializer-list char walk with `":" in args_search_text` -- its only effect is truncating at a top-level `:`, a no-op when the signature has none (the common case). - Guard the c/cpp `#else`/`#elif` preprocessor-branch finditer with `"#" in args_search_text` -- no `#` means no match and no re-slice. - Compute `block.count("\n")` once instead of twice on the (often large) body. cProfile on curl: `_slice_by_braces` tottime 0.370s -> 0.329s (-11% of the per-match Python). Output-identical: full-curl `audit.json`/`sarif.json` byte- identical to main via phase_ab, 290 detector/extraction tests green. End-to-end this is ~0.2% of Optical_Detector -- below the wall-clock noise floor -- so it is a clean-up, not a headline win; see the issue for the full diagnostic. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
#3174) Captures how to A/B a scan-hot-path change honestly (phase telemetry, the phase_ab harness, license key, alternating rounds, A-vs-A control, deterministic surface) and, new here, the perspective this PR crystallized: the scan parallelizes one worker per file, so on a fast many-core box the wall clock hides single-threaded per-worker CPU. A change that is sub-noise on the wall here can matter on core-constrained or slower hosts, where per-worker CPU sits closer to the wall -- so judge per-worker CPU (cProfile tottime / --file-speed phase totals), not just wall on the dev machine, and don't over-claim the mirror image on I/O- or memory-bound hosts either. Co-Authored-By: Claude Opus 4.8 <[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.
Profiling for #3174 overturned its premise (full diagnostic in the issue): the brace scan (
_find_balanced_end) is ~0.5% of the Mode B key — already C-fast — and there's no quadratic re-scan. Mode B's cost is diffuse per-match Python plus per-function block metrics. This PR removes the clearly-wasteful part of the per-match Python.Change (all output-identical)
Three shavings in the
_slice_by_bracesper-match loop:":" in args_search_text— its only effect is truncating at a top-level:, a no-op when the signature has none (the common case).#else/#elifpreprocessor-branchfinditerwith"#" in args_search_text— no#⇒ no match ⇒ no re-slice.block.count("\n")once instead of twice on the (often large) function body.Each guard skips work that provably cannot change the result, so nothing behavioral moves.
Verification
audit.json+sarif.jsonbyte-identical to main (viatests/tools/phase_ab.pyartifact diff)._slice_by_bracestottime 0.370s → 0.329s (−11% of the per-match Python).On the size of the win — read the hardware caveat
End-to-end on the dev box this is ~0.2% of Optical_Detector, below that machine's wall-clock noise floor — but that box has many cores and a fast clock, so galaxyscope's per-file parallelism hides per-worker CPU. This change reduces single-threaded, CPU-bound per-match work; on hosts with fewer cores (per-worker CPU sits closer to the wall) or a slower clock, the same −11% translates more directly to wall time. Framed as a low-risk CPU cleanup that helps most exactly where the engine is most constrained, not a headline number on fast hardware.
Closes #3174 (diagnosed: no headline Mode B lever; brace scan ~0.5%; the dominant Optical_Detector cost is
coding_analysis, already worked by #3069/#3072).🤖 Generated with Claude Code
Also in this PR: speed-testing docs
Adds
docs/perf_speed_testing.md— how to A/B a hot-path change honestly (phase telemetry, thephase_abharness, A-vs-A control, deterministic-surface identity) and the multi-hardware perspective this change surfaced: the scan runs one worker per file, so a fast many-core box hides single-threaded per-worker CPU. A reduction that is sub-noise on the wall here can matter on core-constrained / slower hosts, where per-worker CPU sits closer to the wall. Judge per-worker CPU (cProfiletottime/--file-speedphase totals), not just wall on the dev machine — and don't over-claim the mirror image on I/O- or memory-bound hosts either.