Repository navigation
perf(detection): data-shape fast-exit for wordlist files (#3188) - #3194
Merged
Merged
Conversation
…3188) The Tier 4 discovery funnel scans every candidate language's full ruleset against an extensionless file's whole content. For a data file with no code structure -- haiku's 28,137-line src/apps/mail/words, a bare uppercase-word- per-line dictionary -- that is ~0.9s of pure waste: the funnel finds no lexical family, returns 'undeterminable', and inspect() falls back to the plaintext 'Prose Fallback' anyway. Add a bounded, O(1)-in-file-size pre-check at the top of the funnel: when a file has effectively no structural punctuation ({}()[];=) AND is overwhelmingly one-token-per-line, return that SAME 'undeterminable' verdict up front. Real code can't meet both conditions -- its rules need exactly that punctuation to score -- so the classification is unchanged; only the wasted scan is skipped. Note on scope: the aperture filter's Lexical Monotony gate already rejects these files when they're untracked, but git-tracked repo files (the fleet case, and how #3188 was found) are admitted and reach detection -- which is exactly where this gate fires. Measured (real git-tracked haiku/src/apps/mail, engine at main): words file 1.207s -> 0.257s 3_Language_Detector 1.05s -> 0.02s mail dir pipeline 1.72s -> 0.76s Byte-identical classification: #3117 detection audit unchanged (no regression), golden crucible 0 diffs. 16 + 404 detection/lens/aperture unit tests pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Addresses the
words(wordlist scanned as code) half of #3188. (TheAvailabilityInternal.hhalf's dominant cost — the Tier 3 c-vs-objc lexical tie-break — was already eliminated by #3137; see the investigation comment. Its residual is an analysis-lane optimisation, left for follow-up.)Root cause
haiku's
src/apps/mail/wordsis a 28,137-line bare uppercase-word-per-line dictionary — zero code punctuation. When it reaches the Tier 4 extensionless discovery funnel, the funnel scans every candidate language's full ruleset against the whole 275 KB, finds no lexical family, returnsundeterminable, andinspect()then falls back to plaintext"Prose Fallback". So the correct answer (plaintext) is reached only after ~0.9 s of pure waste.(Why it reaches detection at all when the aperture filter has a Lexical Monotony gate: that gate rejects these files when they're untracked, but git-tracked repo files — the fleet case, and how #3188 surfaced — are admitted and flow to detection. Confirmed by A/B on the real git-tracked tree.)
Fix
A bounded, O(1)-in-file-size pre-check at the top of the discovery funnel: when a file has effectively no structural punctuation (
{}()[];=) and is overwhelmingly one-token-per-line, return the sameundeterminableverdict up front — soinspect()produces the identical plaintext classification, just without the scan. Real code can't satisfy both conditions (its rules need that punctuation to score at all), so nothing that currently classifies as a language can be affected.Measured (real git-tracked
haiku/src/apps/mail, engine atmain)wordsfile3_Language_DetectorphaseSafety
Byte-identical classification — this is a fast-path, not a behaviour change:
🤖 Generated with Claude Code