Repository navigation
perf(#3182): extend the _is_orphan bisect fast path to hyphenated names - #3184
Merged
Merged
Conversation
_is_orphan asks "does this name occur outside its own span?" via an O(log n) bisect over a precomputed occurrence index -- but the index only covered single \w+ tokens, so hyphenated identifier names (COBOL paragraphs, Lisp/Scheme, the column_sensitive family) fell to an O(filesize) per-function boundary-regex rescan (the same O(functions x filesize) quadratic the \w+ fast path exists to prevent -- documented at ~10s on a 1MB, ~900-function header). Index the segment-aligned hyphenated sub-runs of every [\w-]+ token so those names bisect too. Segment alignment makes occ_index[name] exactly the set of (?<!\w)name(?!\w) match starts, so it is byte-identical to the fallback, including the boundary case where a shorter paragraph name matches inside a longer hyphenated token (CALC inside CALC-TOTAL). Single-\w+ names keep the existing code path untouched. Scope/honesty: this bounds a latent quadratic for LARGE single hyphen-name files; it is flat on the current corpus (phase_ab A/B on curl + all_language_repo: wall within the A-vs-A control noise floor). cProfile over-weights _is_orphan ~50x because its real cost is C-level regex scanning -- the flat A/B is ground truth. Landing it as a correctness/robustness bound, not a measured speedup. Verified: function_data (incl. usage_status/sec_dead_code) byte-identical vs baseline across all 11,530 COBOL-corpus functions and all 43,084 all_language_repo functions; audit.json + sarif.json byte-identical both repos. New regression test runs a hyphen-overlap COBOL fixture through the fast path and the monkeypatched fallback and asserts the census agrees. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closed
8 tasks
Contributor
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.
Partial progress on #3182. Honest framing up front: this is a latent-quadratic bound, not a measured corpus speedup.
What
_is_orphan("does this name occur outside its own span?") answers via an O(log n) bisect over a precomputed occurrence index — but the index only covered single\w+tokens. Hyphenated identifier names (COBOL paragraphs, Lisp/Scheme, thecolumn_sensitivefamily) failed that guard and fell to an O(filesize) per-function(?<!\w)name(?!\w)rescan — the same O(functions × filesize) quadratic the\w+fast path exists to prevent (documented at ~10s on a 1MB, ~900-function header).This indexes the segment-aligned hyphenated sub-runs of every
[\w-]+token so those names bisect too. Segment alignment makesocc_index[name]exactly the set of(?<!\w)name(?!\w)match starts — byte-identical to the fallback, including the boundary case where a shorter paragraph name matches inside a longer hyphenated token (CALCinsideCALC-TOTAL). Single-\w+names keep the existing code path untouched.Why it's flat (and why I'm landing it anyway)
I profiled a COBOL-heavy scan under cProfile and
_is_orphanshowed as ~20% of extraction — which is how I found this. But the real-harness A/B (phase_ab.py --rounds 3 --controlon curl + all_language_repo) is flat: wall within the A-vs-A control noise floor, Optical Detector cumulative CPU unchanged. cProfile over-weights_is_orphan~50× because its real cost is C-level regex scanning. The A/B is ground truth.So this bounds the quadratic for a large single hyphen-name file (where it would genuinely bite), but does not move the mixed corpus. Same character as #3175 — a worst-case bound, landed for robustness, not a headline number.
Verification
function_data(incl.usage_status/sec_dead_code) byte-identical vs baseline across all 11,530 COBOL-corpus functions and all 43,084 all_language_repo functions.audit.json+sarif.jsonbyte-identical on both repos.tests/core_engine/test_orphan_hyphen_fast_path_3182.py): runs a hyphen-overlap COBOL fixture through the fast path and the monkeypatched\w+-only fallback and asserts the census agrees.test_unreferenced_by_name_contract_2806,cobol_mainframe/, line-gate tests).Note for #3182 scope
The issue assumed the Optical Detector's COBOL cost could be gated like Security Lens (#3069/#3072/#3173). It can't: see the issue comment I'm posting —
func_start(the dominant real cost, in both thefunc_startrule and_slice_by_labels) has no required literal (it anchors on column position + any identifier) and isn't line-local, so it's ungate-able by the literal-prefilter machinery. The only remaining levers are a parity-critical regex rewrite or trimming the_slice_by_labelsper-function loop — deferred pending a decision on ROI.🤖 Generated with Claude Code