TECHNICAL · COST MODEL
Cost control for morphological search
Morphological knowledge is confined to query plans and bounded decisions around anchors. Corpus-scale work remains byte scanning and streaming output.
Cost separation
Search cost splits into fixed query-plan construction and corpus-dependent scanning. Planning bounds the lexicon analyses and candidate programs. Scanning uses long fixed anchors to minimize the positions that require morphology.
Programs share particle and ending continuations. Only plans with component decisions initialize that resource. Output flows through a capacity-bounded channel. Rule count, corpus size, and result count are controlled at separate boundaries.
Anchors and matchers
Each candidate program selects the longest fixed byte sequence that reduces verification work. A one-syllable anchor always carries a boundary or structural decision.
걷다
├─ 걷고 · 걷는 · 걷지 · 걷겠
├─ 걸어 · 걸었
└─ 걸으 · 걸은 · 걸을
One unique anchor uses memmem::Finder. Small multi-anchor inputs merge finder hits directly; larger cumulative scans build one reusable Aho-Corasick automaton. Both paths expose overlapping candidates in the same order.
Plan limits
Public limits prevent one query from consuming unbounded compile latency or matcher memory.
| Target | Limit | Unit |
|---|---|---|
| Query length | 256 | Unicode scalars |
| Atoms | 32 | per query |
| Analyses | 32 | per atom |
| Candidate programs | 4,096 | per plan |
| Estimated matcher memory | 64 MiB | per plan |
| Continuation depth | 4 | state transitions |
Exceeding a limit causes a compile error. kfind does not silently truncate programs, because a successful partial plan would hide missing inflections.
Resource initialization
A candidate decision is either Boundary or Structural. The component resource is read only when the compiled plan contains a structural program. Literal, token, and any plans do not use it.
Resource bytes must pass schema, release version, source SHA-256, section digest, offset, and component-span validation before installation. A failed manual replacement leaves the active resource intact.
Scan path
| Path | Default | Additional-cost condition |
|---|---|---|
| Anchor scan | Byte search | Anchor hit |
| Span match | Source byte range only | Explanation requested |
| Provenance | Computed on matching lines | JSON or explain output |
| Normalization | Direct NFC anchor search | Canonical mapping or suffix consumption |
| Phrase | Collect atom spans once | Every atom has candidates |
Verified overlaps use leftmost-longest, non-overlapping resolution over core and token spans. Default output does not allocate provenance objects.
Performance-metric boundaries
Startup, lexicon load, query compile, filesystem walk, scan, verification, and output are separate workloads. Fixture cases/s is not corpus throughput. A 1 GiB literal scan does not measure morphology quality or component initialization. Latency, throughput, RSS, and program count retain their own units.