Skip to content

perf(detection): data-shape fast-exit for wordlist files (#3188) - #3194

Merged
squid-protocol merged 1 commit into
mainfrom
fix/3188-wordlist-data-gate
Sep 19, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/3188-wordlist-data-gate

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Addresses the words (wordlist scanned as code) half of #3188. (The AvailabilityInternal.h half'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/words is 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, returns undeterminable, and inspect() 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 same undeterminable verdict up front — so inspect() 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 at main)

before after
words file 1.207 s 0.257 s
3_Language_Detector phase 1.05 s 0.02 s
mail-dir pipeline 1.72 s 0.76 s

Safety

Byte-identical classification — this is a fast-path, not a behaviour change:

🤖 Generated with Claude Code

…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]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 1c25e2c into main Sep 19, 2026
31 checks passed
@squid-protocol
squid-protocol deleted the fix/3188-wordlist-data-gate branch September 19, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant