docs: rename project to obiskim and expand documentation

Rename the project from "obikmer" to "obiskim" across all documentation, user guides, and developer notes. Add extensive new theoretical and implementation documentation covering chance sharing, sibling partition unification, pair-coverage sampling, MPHF batch queries, merge scaling, and hot resume/memoization. Update navigation structures to reflect these new topics and the new project name.

- Rename "obikmer" to "obiskim" in all HTML titles, headers, navigation labels, and code examples across `DevDoc/` and `doc/` directories.
- Add new navigation links for "Chance sharing across genomes", "Sibling partition unification", "Pair-coverage-biased family sampling", "MPHF batch queries", "Merge mmap audit", "Merge scaling", and "Hot resume and memoization" throughout the documentation site.
- Move `DevDoc/architecture/numa_worker_pools/index.html` to `DevDoc/architecture/hot_resume_memoization/index.html` and update content to focus on hot resume and memoization strategies.
- Move `DevDoc/implementation/evidence_elimination/index.html` to `DevDoc/implementation/merge_mmap_audit/index.html` and update content to detail merge mmap audit findings and plans.
- Move `DevDoc/implementation/superkmer.refs/index.html` to `DevDoc/implementation/merge_scaling/index.html` and update content to discuss merge scaling costs and dependencies.
- Move `DevDoc/theory/indexing/index.html` to `DevDoc/theory/chance_sharing/index.html` and rewrite content to discuss chance sharing across genomes and null models.
- Move `DevDoc/theory/minimizer/index.html` to `DevDoc/theory/sibling_partition_unification/index.html` and update content to discuss sibling partition unification and Can3 masked canonical form.
- Add new `DevDoc/implementation/mphf_batch_queries/index.html` documenting MPHF batch query performance and inventory.
- Add new `DevDoc/theory/pair_coverage_sampling/index.html` documenting pair-coverage-biased family sampling theory and diagnostics.
- Update `DevDoc/architecture/query/index.html` to describe `by_partition` using `Vec<PartitionKmers>` instead of `HashMap` for reduced memory usage.
- Update `DevDoc/implementation/merge/index.html` to describe bootstrap output logic selecting base source by largest `unitigs.bin` size and using `MatrixBuilder::resume`.
- Update `DevDoc/implementation/unitig_evidence/index.html` to change `MAX_KMERS_PER_CHUNK` from 256 to 128 and update rank field documentation.
- Update `DevDoc/implementation/obipipeline/index.html` to reflect that `obiskim` uses `make_pipe!` and `.apply()` instead of `make_pipeline!` / `WorkerPool`.
- Update `DevDoc/implementation/filtering/index.html` to change `FilterArgs` inheritance to `obiskim::cmd::predicate::FilterArgs`.
- Update `DevDoc/implementation/partition_layer_cache/index.html` to reflect new crate dependency structure requiring external reachability for algorithm implementation traits.
- Update `doc/formats/index_layout/index.html` to describe new directory structure for index files including `part_NNNNN/index/layer_X/` and updated merging/packing logic.
- Update `doc/formats/vcf/index.html` to use `obiskim` prefixes for contigs and update VCF header source.
- Update `doc/usage/estimate/index.html` to add "Comparing an index with random sharing" section and clarify `--index` and `--presence-threshold` options.
- Update `doc/usage/phylo/index.html` to clarify that running `obiskim phylo` twice draws independent samples and update `--sibling-annex` behavior.
- Update `doc/usage/select/index.html` to clarify that `select` always writes to a new output directory and explains hard-linking mechanism.
- Add new BibTeX entries for Karlin et al. and Bennett et al. in `doc/references.bib`.
- Delete `scripts/smoke_test_index2.sh` which contained end-to-end smoke tests for `obikmer2 index` and `obikmer query`.
- Update `src/Cargo.lock` to bump "obiskim" package dependency from 1.4.8 to 1.4.9.
This commit is contained in:
Eric Coissac committed 2026-12-02 16:12:54 +01:00
1 parent 917cb26186
commit f1b4b4ebda
102 files changed
+27255 -1226

No files matched your search

+350 -20
View File
@@ -19,7 +19,7 @@
<title>Query system - obikmer</title>
<title>Query system - obiskim</title>
@@ -76,7 +76,7 @@
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="../.." title="obikmer" class="md-header__button md-logo" aria-label="obikmer" data-md-component="logo">
<a href="../.." title="obiskim" class="md-header__button md-logo" aria-label="obiskim" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
@@ -90,7 +90,7 @@
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
obikmer
obiskim
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
@@ -134,13 +134,13 @@
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../.." title="obikmer" class="md-nav__button md-logo" aria-label="obikmer" data-md-component="logo">
<a href="../.." title="obiskim" class="md-nav__button md-logo" aria-label="obiskim" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
obikmer
obiskim
</label>
<ul class="md-nav__list" data-md-scrollfix>
@@ -392,6 +392,34 @@
<li class="md-nav__item">
<a href="../../theory/chance_sharing/" class="md-nav__link">
<span class="md-ellipsis">
Chance sharing across genomes (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/evolutionary_distances/" class="md-nav__link">
@@ -414,6 +442,62 @@
<li class="md-nav__item">
<a href="../../theory/sibling_partition_unification/" class="md-nav__link">
<span class="md-ellipsis">
Sibling partition unification (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/pair_coverage_sampling/" class="md-nav__link">
<span class="md-ellipsis">
Pair-coverage-biased family sampling (discussion)
</span>
</a>
</li>
</ul>
</nav>
@@ -670,6 +754,34 @@
<li class="md-nav__item">
<a href="../../implementation/mphf_batch_queries/" class="md-nav__link">
<span class="md-ellipsis">
MPHF batch queries (inventory)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../implementation/unitig_evidence/" class="md-nav__link">
@@ -866,6 +978,62 @@
<li class="md-nav__item">
<a href="../../implementation/merge_mmap_audit/" class="md-nav__link">
<span class="md-ellipsis">
Merge mmap audit (2026-11)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../implementation/merge_scaling/" class="md-nav__link">
<span class="md-ellipsis">
Merge scaling (open)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../implementation/filtering/" class="md-nav__link">
@@ -1144,6 +1312,34 @@
<li class="md-nav__item">
<a href="../hot_resume_memoization/" class="md-nav__link">
<span class="md-ellipsis">
Hot resume and memoization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../numa_worker_pools/" class="md-nav__link">
@@ -1524,6 +1720,45 @@
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#query-memory-partitionkmers-replaces-the-per-partition-hashmap-2026-10-15" class="md-nav__link">
<span class="md-ellipsis">
Query memory: PartitionKmers replaces the per-partition HashMap (2026-10-15)
</span>
</a>
<nav class="md-nav" aria-label="Query memory: PartitionKmers replaces the per-partition HashMap (2026-10-15)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#chunk-size-sweep-on-a-small-input-2026-10-15" class="md-nav__link">
<span class="md-ellipsis">
Chunk size sweep on a small input (2026-10-15)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#automatic-chunk-size-now-follows-the-input-size-2026-10-15" class="md-nav__link">
<span class="md-ellipsis">
Automatic chunk size now follows the input size (2026-10-15)
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
@@ -1561,7 +1796,7 @@
decompose all sequences into superkmers (SuperKmerIter) — construction only,
not the dedup key
deduplicate at k-mer granularity, split by partition in the same pass:
by_partition: Vec&lt;HashMap&lt;CanonicalKmer, Vec&lt;KmerDesc&gt;&gt;&gt; ← KmerDesc = (seq_idx, pos)
by_partition: Vec&lt;PartitionKmers&gt; ← sorted unique k-mers + flat KmerDesc = (seq_idx, pos) slices (2026-10-15, was a HashMap — see &quot;Query memory&quot; below)
allocate SmerIndex (SmerIndex::new): in_index: Vec&lt;bool&gt;, sized total_smers —
NOT multiplied by n_genomes
allocate by_genome: Vec&lt;Vec&lt;(seq_idx, pos, value)&gt;&gt;, one empty Vec per genome —
@@ -1733,7 +1968,7 @@ ATCGATCG...
<p><code>kmer_count + kmer_missing</code> ≤ total k_user-mers in the sequence. The gap corresponds to k_user-mers whose z-window was not fully confirmed (at least one s-mer absent or zero for all genomes) but whose first s-mer was present in the index.</p>
<hr />
<h2 id="cli">CLI</h2>
<div class="highlight"><pre><span></span><code>obikmer query &lt;index&gt; [--detail] [--mismatch] [--count-missing]
<div class="highlight"><pre><span></span><code>obiskim query &lt;index&gt; [--detail] [--mismatch] [--count-missing]
[--force-presence] [--presence-threshold &lt;n&gt;]
[-z &lt;z&gt;] [-T &lt;threads&gt;] [--chunk-size &lt;MiB&gt;]
&lt;query.fa&gt; [&lt;query2.fa&gt; ...]
@@ -1813,7 +2048,7 @@ replacing the <code>CanonicalKmer</code> key by the resolved <code>slot</code> (
<p><strong>7. Partition-level parallelism is currently absent — and a NUMA-aware mechanism for exactly this already exists, unused, in <code>obikindex</code>.</strong>
<code>process_chunk</code>'s partition loop (<code>query.rs:250-278</code>, <code>for (part_idx, part_sks) in by_part.iter().enumerate()</code>) processes every partition of a chunk sequentially on the single worker thread that owns that chunk. This is a parallelism axis on its own, independent of the column question below.
More importantly: <code>docmd/architecture/numa_partition_runner.md</code> and <code>numa_worker_pools.md</code> document <code>PartitionRunner</code> (<code>obikindex/src/numa.rs</code>), <strong>already implemented</strong> and already used by <code>merge.rs</code>, <code>index.rs</code> (<code>build_layers</code>), <code>select.rs</code>, <code>reindex.rs</code>, <code>rebuild.rs</code> — one controller thread per NUMA node, a Rayon pool pinned to that node's CPUs (<code>hwlocality</code>, <code>numa</code> feature, default-on in <code>obikindex/Cargo.toml</code>), adaptive worker activation driven by <em>both</em> a CPU-efficiency signal and an I/O-throughput signal (<code>CpuSample</code>/<code>IoSample</code>, <code>/proc/self/io</code> on Linux). It exists precisely because a naive <code>into_par_iter()</code> on the global Rayon pool measurably degrades ×60 on this codebase's own 192-core/8-NUMA reference machine (<code>numa_worker_pools.md</code>, § Problem) once workers contend for cross-socket memory bandwidth on shared mmap'd/hashed structures — exactly the shape of the matrix-column scan in point 8 below.
<code>obikmer</code> already depends on <code>obikindex</code> (<code>obikmer/Cargo.toml</code>, for <code>KmerIndex</code>), so <code>PartitionRunner</code> is directly reachable from <code>cmd/query.rs</code> — no new dependency. Both the partition-level loop and (see point 8) the genome-column scan should be driven through it rather than through ad-hoc <code>rayon::into_par_iter()</code>, to avoid reproducing the already-measured-and-fixed contention problem. Also relevant: the "CPU-only signal stalls on I/O-bound stages" issue documented for <code>pack_matrices</code> (mmap-heavy, page-fault-bound) applies just as much to a column-major mmap scan over persistent matrices — reuse the existing dual CPU/IO activation signal rather than re-deriving one.</p>
<code>obiskim</code> already depends on <code>obikindex</code> (<code>obiskim/Cargo.toml</code>, for <code>KmerIndex</code>), so <code>PartitionRunner</code> is directly reachable from <code>cmd/query.rs</code> — no new dependency. Both the partition-level loop and (see point 8) the genome-column scan should be driven through it rather than through ad-hoc <code>rayon::into_par_iter()</code>, to avoid reproducing the already-measured-and-fixed contention problem. Also relevant: the "CPU-only signal stalls on I/O-bound stages" issue documented for <code>pack_matrices</code> (mmap-heavy, page-fault-bound) applies just as much to a column-major mmap scan over persistent matrices — reuse the existing dual CPU/IO activation signal rather than re-deriving one.</p>
<blockquote>
<p><strong>Correction from implementation (Phase 4 below)</strong>: this turned out not to be viable as described. <code>PartitionRunner::run()</code>'s actual body spawns roughly one OS thread per worker slot across every NUMA node <strong>on every call</strong> (confirmed by reading <code>numa.rs</code>, not just its doc comments) — fine for the one-call-per-command-invocation batch usage in <code>merge</code>/<code>build_layers</code>, but <code>query_partition_with</code> runs once per <code>(chunk, partition)</code>, far too frequently to absorb that spawn cost. Partition-level parallelism via <code>PartitionRunner</code> is deferred, not implemented. See Phase 4's "What did not ship, and why" for the detail.</p>
</blockquote>
@@ -1834,19 +2069,19 @@ Stage 2's output should be <code>HashMap&lt;genome_idx, Vec&lt;(seq_idx, positio
<p>None of this is implemented yet — parked here as a coherent roadmap while the design is discussed further. Suggested dependency order: (1) I/O parallelism → (3) genome-aware chunk sizing → (4)–(9) staged/k-mer-deduped/NUMA-aware-partition-and-column-major/sparse query engine (larger refactor, biggest structural payoff — reuses <code>PartitionRunner</code> rather than inventing a new parallelism mechanism) → (2) parallel gzip (separate, orthogonal, tracked in chunkreader.md) → secondary diagnostics patterns.</p>
<hr />
<h2 id="implementation-plan">Implementation plan</h2>
<p>Concrete, phased translation of the roadmap above. Phases 0–2 are small, independent, low-risk, and each individually testable against current <code>query</code> output — land them first, in order, and measure on the reference 192-core/8-NUMA machine before deciding whether phases 3–5 (the staged/sparse engine, the larger structural payoff) are still worth their cost. Phases 3–5 are one coordinated change spanning <code>obikmer</code>, <code>obikindex::partition</code>, and <code>obicompactvec</code> — they should not be split across releases mid-way, because the intermediate state (e.g. k-mer-level dedup feeding the old dense <code>KmerResults</code>) has no correctness or performance benefit on its own. Phase 6 is unrelated to phases 0–5 and can happen any time, independently, if <code>rapidgzip-rs</code> is validated (see <a href="../../implementation/chunkreader/#future-work--parallel-gzip-decompression-in-xopen">chunkreader.md</a>).</p>
<p>Concrete, phased translation of the roadmap above. Phases 0–2 are small, independent, low-risk, and each individually testable against current <code>query</code> output — land them first, in order, and measure on the reference 192-core/8-NUMA machine before deciding whether phases 3–5 (the staged/sparse engine, the larger structural payoff) are still worth their cost. Phases 3–5 are one coordinated change spanning <code>obiskim</code>, <code>obikindex::partition</code>, and <code>obicompactvec</code> — they should not be split across releases mid-way, because the intermediate state (e.g. k-mer-level dedup feeding the old dense <code>KmerResults</code>) has no correctness or performance benefit on its own. Phase 6 is unrelated to phases 0–5 and can happen any time, independently, if <code>rapidgzip-rs</code> is validated (see <a href="../../implementation/chunkreader/#future-work--parallel-gzip-decompression-in-xopen">chunkreader.md</a>).</p>
<p>Instrumentation is deliberately sequenced <em>before</em> the I/O fix (reordering the roadmap's own listed order), because every later phase's justification rests on a measurement ("to be measured, not assumed" appears throughout the roadmap above) — without it, phases 3–5 would be undertaken on faith.</p>
<p>Performance measurement on the reference 192-core/8-NUMA machine is done by the project owner, not from this development environment (macOS, 16 cores — <code>PartitionRunner</code>'s NUMA pinning is Linux-only, so even phase 4's mechanism can't be functionally exercised for its actual purpose here). Each phase below is therefore written to be <em>self-measuring</em>: the debug-level logging it adds must be enough, on its own, to judge whether that phase's algorithmic choice paid off from a cluster run's logs, without needing to attach a profiler.</p>
<h3 id="conventions-applied-to-every-phase-below">Conventions applied to every phase below</h3>
<p><strong>Debug logging.</strong> Every phase that changes an algorithmic choice (not phase 0, which <em>is</em> the logging) adds <code>tracing::debug!</code>/<code>trace!</code> at points that let a cluster run's logs answer "did this help": counts, ratios, and timings that quantify the specific claim that phase makes — e.g. phase 3 must log how many MPHF <code>find</code> calls were saved by k-mer-level dedup (the whole justification for that phase), phase 4 must log per-column scan timings, phase 5 must log actual retained-memory / sparsity ratios achieved. Prefer one structured <code>debug!</code> per chunk (fields, not prose) over free-text — the cluster logs will be the only evidence available for judging these choices, so they need to be grep/awk-able, not just readable.</p>
<p><strong>Unit tests.</strong> This project's convention (<code>obiread</code>, <code>obikseq</code>, <code>obidebruinj</code>, <code>obicompactvec</code>, <code>obikindex::layer</code>, <code>obiskio</code>, <code>obifastwrite</code>) is <code>#[cfg(test)] #[path = "tests/&lt;name&gt;.rs"] mod tests;</code> at the bottom of the source file, with the actual test code in a sibling <code>src/tests/&lt;name&gt;.rs</code>. Neither <code>obikmer</code> nor <code>obikindex::partition</code> (the two crates phases 3 and 5 touch most) currently have a <code>src/tests/</code> directory at all — this needs creating, following the existing pattern exactly, not inventing a new one.</p>
<p><strong>Unit tests.</strong> This project's convention (<code>obiread</code>, <code>obikseq</code>, <code>obidebruinj</code>, <code>obicompactvec</code>, <code>obikindex::layer</code>, <code>obiskio</code>, <code>obifastwrite</code>) is <code>#[cfg(test)] #[path = "tests/&lt;name&gt;.rs"] mod tests;</code> at the bottom of the source file, with the actual test code in a sibling <code>src/tests/&lt;name&gt;.rs</code>. Neither <code>obiskim</code> nor <code>obikindex::partition</code> (the two crates phases 3 and 5 touch most) currently have a <code>src/tests/</code> directory at all — this needs creating, following the existing pattern exactly, not inventing a new one.</p>
<p><strong>Workflow (<code>jj</code>).</strong> Work happens in a fresh <code>jj</code> commit, easy to abandon. <code>jj new</code> between phases is reasonable where it helps isolate a phase for review, but only when the working copy compiles at that point (project convention) — phase 3's internal sub-steps (batch dedup change, then <code>query_layer.rs</code> split, then the new return shape) will likely not each compile independently since they're one coupled change, so treat "commit boundary" and "plan phase boundary" as related but not forced to match 1:1; use judgement per phase rather than mechanically splitting on every bullet.</p>
<h3 id="phase-0-instrumentation-prerequisite-for-measuring-every-later-phase">Phase 0 — Instrumentation (prerequisite for measuring every later phase)</h3>
<p><strong>Goal</strong>: make core utilization, throughput, and per-stage timing visible on a real run, so phases 1–5 can be justified with numbers instead of assumption.</p>
<ul>
<li><code>obikmer/src/cmd/query.rs</code>: wrap <code>run()</code>'s main loop with <code>obisys::Reporter</code>/<code>Stage::start("query")</code>/<code>.stop()</code>, printed at the end via <code>rep.print()</code> — same pattern as <code>index.rs</code>/<code>filter.rs</code>.</li>
<li><code>obiskim/src/cmd/query.rs</code>: wrap <code>run()</code>'s main loop with <code>obisys::Reporter</code>/<code>Stage::start("query")</code>/<code>.stop()</code>, printed at the end via <code>rep.print()</code> — same pattern as <code>index.rs</code>/<code>filter.rs</code>.</li>
<li>Add an <code>obisys::spinner("query")</code> progress bar around the <code>pipe.apply(...)</code> loop, with an EMA throughput readout (bases/s or k-mers/s, mirroring <code>steps::scatter</code>'s <code>ema_rate</code> computation, <code>scatter.rs:88-118</code>) and live gauges for "chunks in flight" / "workers busy" — reuse the <code>AtomicU32</code> counter pattern from <code>scatter.rs</code> (<code>flat_active</code>, <code>transform_active</code>) rather than inventing a new one.</li>
<li>Add <code>max_open_files: Option&lt;usize&gt;</code> to <code>QueryArgs</code> and a <code>effective_max_open()</code> method mirroring <code>CommonArgs::effective_max_open()</code> (<code>obikmer/src/cli.rs:90-94</code>) — needed by phase 1's <code>throttle()</code> call. (<code>QueryArgs</code> can't just embed <code>CommonArgs</code> — it doesn't take <code>kmer_size</code>/<code>minimizer_size</code>/<code>partitions</code>/<code>level_max</code>/<code>theta</code> from the CLI, those come from the index metadata — so this is a small standalone addition, not a flatten.)</li>
<li>Add <code>max_open_files: Option&lt;usize&gt;</code> to <code>QueryArgs</code> and a <code>effective_max_open()</code> method mirroring <code>CommonArgs::effective_max_open()</code> (<code>obiskim/src/cli.rs:90-94</code>) — needed by phase 1's <code>throttle()</code> call. (<code>QueryArgs</code> can't just embed <code>CommonArgs</code> — it doesn't take <code>kmer_size</code>/<code>minimizer_size</code>/<code>partitions</code>/<code>level_max</code>/<code>theta</code> from the CLI, those come from the index metadata — so this is a small standalone addition, not a flatten.)</li>
<li>Add one structured <code>debug!</code> per <code>process_chunk</code> call: chunk byte size, sequence count, s-mer count, wall time, and (once later phases exist) the fields they add — this single log line is the baseline every later phase's own logging gets compared against.</li>
<li><strong>Validation</strong>: none needed beyond "the numbers appear and look sane" — this phase changes no query logic or output.</li>
<li><strong>Deliverable used by every phase below</strong>: a before/after throughput and core-utilization measurement on the reference machine.</li>
@@ -1854,7 +2089,7 @@ Stage 2's output should be <code>HashMap&lt;genome_idx, Vec&lt;(seq_idx, positio
<h3 id="phase-1-parallel-per-file-io-fixes-root-cause-of-low-core-utilization">Phase 1 — Parallel per-file I/O (fixes root cause of low core utilization)</h3>
<p><strong>Goal</strong>: file opening, decompression, and chunk-boundary parsing run across the <code>n_workers</code> pool instead of serially in the pipe's dedicated source thread.</p>
<ul>
<li><code>obikmer/src/cmd/query.rs</code>:</li>
<li><code>obiskim/src/cmd/query.rs</code>:</li>
<li>Replace the <code>paths.into_iter().flat_map(read_sequence_chunks_sized(...))</code> construction (current <code>run()</code>, building <code>all_chunks</code>) with <code>obipipeline::throttle(paths.into_iter(), args.effective_max_open())</code>, passed as the pipe's <code>input</code>.</li>
<li>Add a new <code>QueryData::Path(PathBuf)</code> variant (alongside <code>Chunk</code>/<code>Output</code>) to carry the throttled path through the pipe's type-erasure mechanism.</li>
<li>Add a new <strong>first</strong> pipe stage, <code>Flat</code>/fallible (<code>||?</code>), modeled on <code>scatter.rs:60-86</code> and <code>superkmer.rs:54-65</code>: given a <code>Throttled&lt;PathBuf&gt;</code>, call <code>read_sequence_chunks_sized(path, chunk_bytes)</code> and yield each <code>Rope</code> chunk, keeping <code>pw.guard</code> alive until the file's iterator is exhausted (reuse or adapt <code>scatter.rs</code>'s <code>GuardedIter</code> wrapper — same lifetime problem, same fix).</li>
@@ -1867,7 +2102,7 @@ Stage 2's output should be <code>HashMap&lt;genome_idx, Vec&lt;(seq_idx, positio
<h3 id="phase-2-genome-aware-chunk-size-formula-fixes-oom">Phase 2 — Genome-aware chunk-size formula (fixes OOM)</h3>
<p><strong>Goal</strong>: <code>chunk_bytes</code> reflects actual per-chunk memory (<code>O(n_genomes)</code>), not a fixed multiplier.</p>
<ul>
<li><code>obikmer/src/cmd/query.rs</code>, <code>run()</code>: <code>n_genomes</code> and <code>args.detail</code> are already computed above the <code>chunk_bytes</code> calculation (<code>n_genomes</code> at the top of <code>run()</code>, before line 407 in the current file) — reorder if needed, then replace:
<li><code>obiskim/src/cmd/query.rs</code>, <code>run()</code>: <code>n_genomes</code> and <code>args.detail</code> are already computed above the <code>chunk_bytes</code> calculation (<code>n_genomes</code> at the top of <code>run()</code>, before line 407 in the current file) — reorder if needed, then replace:
<div class="highlight"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">computed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">avail</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="p">(</span><span class="n">n_workers</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u64</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">16</span><span class="p">);</span>
</code></pre></div>
with a formula that scales the divisor by <code>n_genomes</code> (and roughly doubles it when <code>--detail</code> is set, since <code>cov</code> duplicates the per-genome accumulation): e.g. <code>per_chunk_multiplier = base_overhead + n_genomes as u64 * BYTES_PER_KMER_PER_GENOME * if detail { 2 } else { 1 }</code>, replacing the flat <code>16</code>. <code>BYTES_PER_KMER_PER_GENOME</code> should be derived from <code>KmerResults</code>'s actual layout (<code>4</code> bytes per <code>u32</code> entry in <code>data</code>, plus the <code>bool</code> in <code>in_index</code>, plus <code>win_min</code>'s equal-sized buffer) rather than guessed.</li>
@@ -1879,7 +2114,7 @@ Stage 2's output should be <code>HashMap&lt;genome_idx, Vec&lt;(seq_idx, positio
<h3 id="phase-3-k-mer-level-dereplication-staged-mphfmatrix-lookup">Phase 3 — K-mer-level dereplication, staged MPHF/matrix lookup</h3>
<p><strong>Goal</strong>: replace superkmer-level dedup with k-mer-level dedup (roadmap point 5), and split the fused MPHF-find/matrix-fetch (point 4) so stage 1's output is bucketed by layer and MPHF slot (point 6).</p>
<ul>
<li><code>obikmer/src/cmd/query.rs</code>:</li>
<li><code>obiskim/src/cmd/query.rs</code>:</li>
<li>Replace <code>QueryBatch::from_records</code>'s dedup map (<code>HashMap&lt;RoutableSuperKmer, Vec&lt;SKDesc&gt;&gt;</code>, current <code>query.rs:112</code>) with a per-partition <code>HashMap&lt;CanonicalKmer, Vec&lt;(seq_idx: u32, pos: u32)&gt;&gt;</code>, built in the same <code>SuperKmerIter</code> pass: superkmer construction and partition routing (<code>part_idx</code> from the superkmer's minimizer hash) are unchanged, only the granularity of what gets deduplicated changes — each <code>CanonicalKmer</code> within a superkmer is inserted individually instead of the whole superkmer being the dedup key.</li>
<li><strong>Verified</strong>: <code>CanonicalKmer</code> (<code>obikseq/src/kmer.rs:390</code>, <code>pub type CanonicalKmer = CanonicalKmerOf&lt;KLen&gt;</code>) — the underlying <code>CanonicalKmerOf&lt;L&gt;</code> derives <code>Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash</code> (<code>kmer.rs:269</code>). Usable as a <code>HashMap</code>/<code>HashSet</code> key as-is, no change needed.</li>
<li><code>obikindex/src/partition/query_layer.rs</code>:</li>
@@ -1888,14 +2123,14 @@ Stage 2's output should be <code>HashMap&lt;genome_idx, Vec&lt;(seq_idx, positio
<li>New return shape for the partition-level query, replacing today's <code>on_hit(sk_idx, kmer_idx, row)</code> callback: <code>HashMap&lt;layer_idx, HashMap&lt;slot, Vec&lt;(seq_idx, pos)&gt;&gt;&gt;</code> (roadmap point 6) — built directly from the k-mer dedup map's <code>Vec&lt;(seq_idx,pos)&gt;</code> values, keyed by the resolved slot instead of the k-mer.</li>
<li><strong>This phase alone has no throughput benefit yet</strong> (matrix fetch still happens, just deferred) beyond the k-mer-level dedup itself (fewer MPHF calls when queries have overlapping/repeated k-mers) — its purpose is to produce the input phase 4 needs. Land phase 3+4 together, not phase 3 alone, per the "don't split 3–5 across releases" note above.</li>
<li>Log, per chunk: total k-mer occurrences vs. unique <code>CanonicalKmer</code> count (the dedup ratio — the entire justification for this phase) and the resulting MPHF <code>find</code> call count. If the dedup ratio is close to <code>1.0</code> on real query data (little redundancy), that's the cluster run telling us this phase wasn't worth it — the logging needs to be able to say that, not just confirm the happy path.</li>
<li><strong>Unit tests</strong>: create <code>obikmer/src/cmd/tests/query.rs</code> (new <code>src/tests/</code> dir for this crate, following the project's <code>#[cfg(test)] #[path = "tests/query.rs"] mod tests;</code> convention) and <code>obikindex/src/partition/tests/query_layer.rs</code> (likewise new for this crate). Cover: the k-mer-level dedup map construction on synthetic sequences with known repeated/overlapping k-mers (assert unique-kmer count and occurrence lists); the <code>find_slot</code>/bucket-by-layer-and-slot construction against a small hand-built <code>QueryLayer</code> fixture, asserting the <code>(layer_idx, slot, seq_idx, pos)</code> tuples match what the old per-occurrence loop would have produced.</li>
<li><strong>Unit tests</strong>: create <code>obiskim/src/cmd/tests/query.rs</code> (new <code>src/tests/</code> dir for this crate, following the project's <code>#[cfg(test)] #[path = "tests/query.rs"] mod tests;</code> convention) and <code>obikindex/src/partition/tests/query_layer.rs</code> (likewise new for this crate). Cover: the k-mer-level dedup map construction on synthetic sequences with known repeated/overlapping k-mers (assert unique-kmer count and occurrence lists); the <code>find_slot</code>/bucket-by-layer-and-slot construction against a small hand-built <code>QueryLayer</code> fixture, asserting the <code>(layer_idx, slot, seq_idx, pos)</code> tuples match what the old per-occurrence loop would have produced.</li>
</ul>
<h3 id="phase-4-column-major-matrix-fetch-roadmap-points-78-implemented-numa-parallelism-deferred">Phase 4 — Column-major matrix fetch (roadmap points 7–8) — implemented, NUMA parallelism deferred</h3>
<p><strong>Goal (revised during implementation)</strong>: replace <code>fill_row</code>-per-hit (row-major, worst-case mmap locality) with a column-major scan. <code>PartitionRunner</code> turned out to be the wrong mechanism for this at this call granularity — see below; the column-major fetch itself is implemented and validated, without it.</p>
<p><strong>What shipped:</strong>
- <code>obicompactvec</code>: the per-column accessors this phase needed <strong>already existed</strong> — <code>PersistentCompactIntMatrix::col_view(c)</code> and <code>PersistentBitMatrix::col_view(c)</code> are public, and <code>IntSliceView::get(slot)</code>/<code>BitSliceView::get(slot)</code> are public — the original plan underestimated how much of this plumbing the pairwise-distance code (<code>dump</code>/<code>select</code>/<code>stats</code>) had already required. The one real gap: <code>PersistentBitMatrix::col_view()</code> panics on the <code>Implicit</code> variant (the documented mono-genome fast path, <code>bitmatrix.rs</code>). Added <code>PersistentBitMatrix::get(c, slot) -&gt; u32</code> (<code>bitmatrix.rs</code>), a non-panicking column-major point lookup that returns <code>1</code> for <code>Implicit</code> regardless of <code>c</code> — the smallest surface needed, not a new <code>col_get</code> API from scratch.
- <code>obikindex/src/partition/query_layer.rs</code>: <code>query_partition_with</code> is now two explicit stages, matching roadmap points 6–8: <strong>stage 1</strong> (MPHF-only, per unique k-mer, bucket hits by <code>(layer_idx, slot)</code>, emits <code>QueryHit::Found</code>) then <strong>stage 2</strong> (per layer with ≥1 hit, column-major: for each genome column <code>g</code> in <code>0..layer.n_cols().min(n_genomes)</code>, scan that layer's bucketed slots and call <code>col_value(g, slot)</code>, emitting <code>QueryHit::Value(descs, g, value)</code> on nonzero). <code>QueryHit</code> is a single enum delivered through one <code>FnMut(QueryHit)</code> callback — an earlier two-closure design (<code>on_found</code> + <code>on_value</code>) didn't borrow-check, since the caller's single mutable accumulator (<code>KmerResults</code>) can't be captured by two separate <code>FnMut</code> closures passed to the same call.
- <code>obikmer/src/cmd/query.rs</code>: <code>KmerResults::set</code> (row-major, whole-row-at-once) replaced by <code>mark_found</code> (stage 1: flag a position as indexed, independent of any genome's value) and <code>set_one</code> (stage 2: write one genome's value at one position). <code>QueryStats</code> extended with <code>n_columns_scanned</code>/<code>n_col_get_calls</code>, logged per chunk.
- <code>obiskim/src/cmd/query.rs</code>: <code>KmerResults::set</code> (row-major, whole-row-at-once) replaced by <code>mark_found</code> (stage 1: flag a position as indexed, independent of any genome's value) and <code>set_one</code> (stage 2: write one genome's value at one position). <code>QueryStats</code> extended with <code>n_columns_scanned</code>/<code>n_col_get_calls</code>, logged per chunk.
- Total <code>get()</code>-equivalent calls are unchanged from the row-major version (<code>n_hits × n_cols</code> in the worst case, confirmed by <code>n_col_get_calls</code> in the debug log) — the win is locality (sequential access within one layer's column at a time, across <code>mmap</code>'d regions, instead of jumping across all columns per hit), exactly as predicted.</p>
<p><strong>What did not ship, and why — <code>PartitionRunner</code> is architecturally the wrong tool here:</strong>
Reading <code>obikindex/src/numa.rs</code>'s actual <code>run()</code> body (not just its doc comments) shows every call spawns a timer thread <strong>plus one OS thread per worker slot on every NUMA node</strong> (<code>std::thread::scope</code> + one <code>s.spawn()</code> per node per <code>max_workers</code>) — on the 192-core/8-NUMA reference machine, that's on the order of 190+ fresh OS threads spawned <strong>per call</strong>. This is fine for its actual, established usage in this codebase (<code>merge.rs</code>, <code>index.rs</code>'s <code>build_layers</code>): one <code>PartitionRunner::new()</code> + one <code>run()</code> call per command invocation, amortised over a batch of ~256 long-running partitions. It is not fine for <code>query</code>'s call pattern: <code>query_partition_with</code> runs once per <code>(chunk, partition)</code>, potentially thousands of times per second — spawning ~190 OS threads that often to scan a handful of genome columns would very likely cost far more than the row-major approach it's meant to replace. This is exactly the "resolve empirically, don't assume" composition risk the roadmap flagged, just resolved by reading the mechanism's actual cost before wiring it in, rather than by measuring a regression on the cluster after the fact.
@@ -1907,14 +2142,14 @@ The column-major loop in stage 2 is therefore a <strong>plain sequential loop</s
<h3 id="phase-5-sparse-findere-rework-roadmap-point-9">Phase 5 — Sparse Findere rework (roadmap point 9)</h3>
<p><strong>Goal</strong>: replace the dense <code>KmerResults</code>/<code>win_min</code> sliding-window scan with one operating on phase 4's sparse per-genome output.</p>
<ul>
<li><code>obikmer/src/cmd/query.rs</code>, <code>process_chunk</code>:</li>
<li><code>obiskim/src/cmd/query.rs</code>, <code>process_chunk</code>:</li>
<li>Remove <code>KmerResults</code> (<code>query.rs:157-202</code>) and the dense <code>win_min</code> allocation (<code>query.rs:290-291</code>, sized <code>max_n_kmers × n_genomes</code>).</li>
<li>Keep a lightweight dense <code>in_index: Vec&lt;bool&gt;</code> per chunk (sized <code>total_kmers</code>, independent of <code>n_genomes</code>) from phase 3's stage 1 — still needed for <code>kmer_missing</code> bookkeeping (leftmost-s-mer-of-window membership test), which phase 4's sparse structure doesn't carry (a k-mer with no genome hit has no entry there at all).</li>
<li>New per-<code>(seq_idx, genome)</code> scan: for each genome's <code>Vec&lt;(seq_idx, pos, count)&gt;</code> (sorted, per phase 4), group by <code>seq_idx</code> (contiguous after sort), then within each sequence's positions detect runs of <code>pos, pos+1, pos+2, ...</code> of length ≥ <code>z</code>; within each run, the existing monotone-deque window-minimum logic (<code>query.rs</code>'s current <code>dq</code> loop, conceptually unchanged) applies — but the deque now only scans real entries in the run, never zero-filled gaps.</li>
<li>Update <code>SeqAcc</code> accumulation and <code>emit_batch</code> to consume this per-genome sparse iteration instead of <code>results.val</code>/<code>results.is_in_index</code>.</li>
<li><code>--detail</code>/<code>cov</code>: build sparsely during the same scan (only positions with a confirmed contribution get an entry), densify into the <code>[u32]</code> JSON array only in <code>emit_batch</code>, only for genomes/sequences actually being serialized (per roadmap point 9's note, <code>query.rs:304-308</code>'s current dense allocation goes away).</li>
<li>Log, per chunk: total sparse entries retained vs. what the old dense <code>KmerResults</code> would have allocated (<code>total_smers × n_genomes</code>) — the sparsity ratio is this phase's entire reason for existing, so it must be directly visible in the logs, not inferred from process RSS. Also log the run-detection stats (number of runs found, average run length) — a low average run length relative to <code>z</code> would mean most positions still fail to form a full window, worth knowing.</li>
<li><strong>Unit tests</strong>: <code>obikmer/src/cmd/tests/query.rs</code> (extended from phase 3) — the property test described below is the primary deliverable here, not an afterthought; write it as an actual <code>#[test]</code> (or a small internal fuzz/property-style loop over randomized fixtures if a property-testing crate isn't already a dependency — check before adding one, per this project's dependency-approval rule) rather than a one-off manual comparison.</li>
<li><strong>Unit tests</strong>: <code>obiskim/src/cmd/tests/query.rs</code> (extended from phase 3) — the property test described below is the primary deliverable here, not an afterthought; write it as an actual <code>#[test]</code> (or a small internal fuzz/property-style loop over randomized fixtures if a property-testing crate isn't already a dependency — check before adding one, per this project's dependency-approval rule) rather than a one-off manual comparison.</li>
<li><strong>Validation — this is the correctness-critical phase</strong>: property-test comparing old (dense, pre-phase-3) and new (sparse) implementations on the same randomized input/index fixtures, asserting identical <code>kmer_count</code>, <code>kmer_missing</code>, <code>kmer_strict_matches</code>, and (with <code>--detail</code>) <code>coverage</code> for every sequence. Keep both implementations compiled side by side (behind a debug-only flag or a temporary parallel code path) only for the duration of this validation; delete the dense path once parity is confirmed — per this project's own convention, superseded code is not kept "just in case."</li>
<li><strong>Update <code>docmd/architecture/query.md</code> itself</strong>: once this phase lands, the "Findere z-window filter" section (which currently — correctly — describes the dense deque-over-<code>0..n_smers</code> scan) needs another pass to describe the sparse run-detection algorithm instead, as already flagged when this phase was discussed.</li>
</ul>
@@ -1923,7 +2158,7 @@ The column-major loop in stage 2 is therefore a <strong>plain sequential loop</s
- New <code>sparse_findere_for_genome(hits, z, presence, threshold) -&gt; (Vec&lt;ConfirmedHit&gt;, n_runs, total_run_len)</code> (<code>query.rs</code>): sorts one genome's raw hits by <code>(seq_idx, pos)</code>, detects maximal runs of consecutive <code>pos</code> within one sequence, runs the same monotone-deque window-minimum as before but scoped to each run (run-relative indices for eviction, absolute <code>pos</code> for computing <code>pos_out</code>). Presence/count adjustment (<code>u32::from(win_min &gt;= threshold)</code> vs. raw) is applied inside this function, once per confirmed hit, rather than later during accumulation.
- <code>process_chunk</code> restructured into three passes after the partition loop: (1) run <code>sparse_findere_for_genome</code> per genome, collecting <code>confirmed_by_genome</code> and run-detection stats; (2) accumulate <code>genome_totals</code> directly from <code>confirmed_by_genome</code> and mark a <code>confirmed_any: Vec&lt;bool&gt;</code> (sized <code>total_kmers_out</code>, not <code>× n_genomes</code>); (3) a position-only pass (<code>O(total_kmers_out)</code>, no genome factor) computing <code>kmer_count</code>/<code>kmer_missing</code> from <code>confirmed_any</code> + <code>SmerIndex</code>. <code>cov</code> (<code>--detail</code>) is populated by re-scanning <code>confirmed_by_genome</code> — only when <code>--detail</code> is actually set, otherwise skipped entirely.
- Debug log added (<code>"sparse Findere"</code>): <code>n_dense_would_be</code> (<code>n_occurrences × n_genomes</code> — what the deleted dense path would have allocated), <code>n_sparse_entries</code> (what's actually retained), <code>n_runs</code>/<code>avg_run_len</code> (per the plan's ask, to see whether hits mostly fail to form complete windows).
- <strong>Unit tests</strong>: <code>sparse_findere_matches_dense_reference_on_random_inputs</code> (<code>obikmer/src/cmd/tests/query.rs</code>) — 200 randomized cases (sequence count/length, <code>z</code>, presence/count mode, threshold, hit density from sparse to fully-dense) comparing <code>sparse_findere_for_genome</code> against <code>dense_reference_findere</code>, a faithful reimplementation of the deleted dense algorithm kept only as a test-local correctness oracle (no property-testing crate added — checked first, none was a workspace dependency; a small <code>std</code>-only xorshift64 PRNG stands in for one, deterministic and dependency-free). All 200 cases pass.
- <strong>Unit tests</strong>: <code>sparse_findere_matches_dense_reference_on_random_inputs</code> (<code>obiskim/src/cmd/tests/query.rs</code>) — 200 randomized cases (sequence count/length, <code>z</code>, presence/count mode, threshold, hit density from sparse to fully-dense) comparing <code>sparse_findere_for_genome</code> against <code>dense_reference_findere</code>, a faithful reimplementation of the deleted dense algorithm kept only as a test-local correctness oracle (no property-testing crate added — checked first, none was a workspace dependency; a small <code>std</code>-only xorshift64 PRNG stands in for one, deterministic and dependency-free). All 200 cases pass.
- <strong>Functional validation performed</strong>: full workspace build + <code>cargo test --workspace</code>, zero failures. End-to-end against real indexes: baseline output (no flags) unchanged from pre-phase-5 recorded values on the same fixtures; <code>--count-missing</code> correct (<code>kmer_missing: 0</code> on a self-match); <code>--detail</code> correct — coverage array length matches <code>kmer_count</code>, and critically, re-ran the two-genome cross-contamination check from phase 4 with <code>--detail --count-missing</code>: <code>genomeA</code> reads show coverage sum <code>106</code> for <code>genomeA</code> and <code>0</code> for <code>genomeB</code> (and vice versa) — confirms the sparse-to-dense <code>cov</code> reconstruction doesn't leak across genomes either, not just the scalar <code>kmer_strict_matches</code> path.
- This phase's roadmap item ("update the Findere z-window filter section") — done, see above; the "Algorithm" section's pseudocode was also updated, since it still named <code>KmerResults</code>/<code>SKDesc</code> from before phases 3–4.</p>
<h3 id="phase-6-parallel-gzip-decompression-independent-optional">Phase 6 — Parallel gzip decompression (independent, optional)</h3>
@@ -1934,6 +2169,101 @@ The column-major loop in stage 2 is therefore a <strong>plain sequential loop</s
<li><strong><code>obicompactvec</code> API surface growth</strong> (phase 4): new public per-column accessors are additive (existing <code>fill_row</code>/<code>row</code> stay for other callers — <code>dump</code>, <code>select</code>, distance computations) — no breaking change expected, but worth checking <code>obicompactvec</code>'s other callers aren't already relying on <code>fill_row</code> being the only/cheapest access path in a way that would make maintaining two access patterns (row-major and column-major) a real maintenance cost rather than a one-off addition.</li>
<li><strong><code>PersistentBitMatrix::Implicit</code>'s hardcoded <code>n_cols: 1</code> — resolved, not a bug.</strong> <code>LayerMeta</code>'s own doc comment (<code>obicompactvec/src/layer_meta.rs:1-9</code>) states it is written "alongside <code>mphf.bin</code>" and read by <code>PersistentBitMatrix::open</code> "to determine <code>n_rows</code> for <strong>the implicit (mono-genome presence/absence) case</strong>" — i.e. <code>Implicit</code> is a documented single-genome fast path (no presence matrix needed when there is trivially one genome), not a generic "no matrix built yet" fallback. <code>n_cols: 1</code> is correct by design for the case it's meant to handle. Phase 4's column loop is safe as planned — this was worth checking once, doesn't need further action.</li>
</ul>
<h2 id="query-memory-partitionkmers-replaces-the-per-partition-hashmap-2026-10-15">Query memory: <code>PartitionKmers</code> replaces the per-partition <code>HashMap</code> (2026-10-15)</h2>
<p><strong>Problem.</strong> A full-size query (two ~450 MB fastq.gz of a skim against a 354 M-kmer index) reached <strong>74–81 GB RSS</strong> with the default 256 MiB chunk. Cause, read in <code>batch.rs</code>/<code>chunk.rs</code> and measured with the <code>by_partition memory retained</code> debug log: <code>QueryBatch::by_partition</code> was a <code>HashMap&lt;CanonicalKmer, Vec&lt;KmerDesc&gt;&gt;</code> per partition. On genomic reads almost every k-mer is unique (12.5 M unique for 13.5 M occurrences in a 48 MB chunk, a dedup of 8 %), so each k-mer paid a table slot, growth slack and its own heap <code>Vec</code>: <strong>889 MB per 48 MB chunk, ~71 bytes per unique k-mer, 18× the chunk size</strong> — the dominant term of the per-chunk memory, several chunks being in flight at once.</p>
<p><strong>Change.</strong> <code>obikquery::PartitionKmers</code>: occurrences collected as <code>(kmer, KmerDesc)</code> per partition, sorted by <code>(kmer, seq_idx, pos)</code> and stored as three flat arrays (unique k-mers, u32 offsets, descs). <code>query_partition_with</code> takes <code>&amp;PartitionKmers</code>; <code>QueryHit</code> already carried slices. Occurrence order per k-mer is unchanged (query order); no per-k-mer allocation.</p>
<p><strong>Measured</strong> (same inputs, release build, identical sorted output digests before and after):</p>
<table>
<thead>
<tr>
<th></th>
<th><code>by_partition</code> (48 MB chunk)</th>
<th>RSS, 2×48 MB chunks</th>
<th>RSS, full run (≈ 1 GB reads)</th>
<th>wall, full run</th>
</tr>
</thead>
<tbody>
<tr>
<td>before</td>
<td>889 MB</td>
<td>5.6 GB</td>
<td>73.7–80.7 GB</td>
<td>135–172 s (one 312 s outlier)</td>
</tr>
<tr>
<td>after</td>
<td>259 MB</td>
<td>4.1 GB</td>
<td><strong>28.2 GB</strong></td>
<td><strong>103 s</strong></td>
</tr>
</tbody>
</table>
<p>With <code>--chunk-size 4</code> the same small query peaks at 3.6 GB: that floor is the touched pages of the index itself, so after the change the remaining per-chunk anonymous memory is ≈ 6× the chunk size, below the formula's factor 12 (<code>BASE_OVERHEAD + 8·n_genomes</code>, still a conservative bound — left unchanged). The sort replaces hashing in <code>from_records</code> and was not slower (17.3 s vs 21.2 s on the small test).</p>
<p><strong>Side finding.</strong> The 256 MiB cap makes small inputs poorly parallel: the two 48 MB files above are two chunks, so two workers; with <code>--chunk-size 4</code> the same query takes 3.7 s instead of 17 s. Not changed here.</p>
<p><strong>Not verified.</strong> Prod-scale (192 workers × 256 MiB chunks in flight): the factor is now ≈ 6 instead of ≈ 21, but how many chunks are in flight at once on that machine was not observed.</p>
<h3 id="chunk-size-sweep-on-a-small-input-2026-10-15">Chunk size sweep on a small input (2026-10-15)</h3>
<p>Input: 2 × 48 MB decompressed fastq (200 000 reads each) against a 354 M-kmer single-genome index (4 partitions), 16 cores on AC power, 3 runs per size, sorted outputs identical (same md5) for every size:</p>
<table>
<thead>
<tr>
<th><code>--chunk-size</code> (MiB)</th>
<th>chunks</th>
<th>wall (s)</th>
<th>user CPU (s)</th>
<th>RSS (GB)</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>~50</td>
<td>2.5–2.6</td>
<td>25.0–25.3</td>
<td>3.2</td>
</tr>
<tr>
<td>4</td>
<td>~25</td>
<td>2.5–2.7</td>
<td>24.3–25.5</td>
<td>3.5</td>
</tr>
<tr>
<td>8</td>
<td>~12</td>
<td>2.5–2.7</td>
<td>23.6–26.1</td>
<td>4.1</td>
</tr>
<tr>
<td>16</td>
<td>~6</td>
<td>4.4</td>
<td>23.1–23.7</td>
<td>4.1</td>
</tr>
<tr>
<td>32</td>
<td>4</td>
<td>8.3</td>
<td>22.9–23.0</td>
<td>4.0</td>
</tr>
<tr>
<td>64 and 256 (default)</td>
<td>2</td>
<td>11.6–11.8</td>
<td>22.4–22.9</td>
<td>4.1</td>
</tr>
</tbody>
</table>
<p>Wall time follows the number of chunks (one worker per chunk) until it reaches the core count, then plateaus at ≈ total CPU / cores; total CPU is almost constant (≈ +10 % at 2 MiB, per-chunk fixed cost, here with 1 genome and 4 partitions). With the 256 MiB cap, <strong>any input below ≈ 16 × 256 MiB = 4 GiB decompressed leaves cores idle</strong>. A rule such as <code>chunk ≈ input_bytes / (workers × 2)</code> with a floor of 4–8 MiB would use all cores on small inputs — <strong>implemented, see below</strong>. Unmeasured: the per-chunk cost on an index with many genomes and 256 partitions, which could move the floor up.</p>
<h3 id="automatic-chunk-size-now-follows-the-input-size-2026-10-15">Automatic chunk size now follows the input size (2026-10-15)</h3>
<p><code>cmd/query/mod.rs</code>: when <code>--chunk-size</code> is not given, the memory-derived size (unchanged: <code>available RAM / (workers × overhead × 2)</code>, clamped to 4–256 MiB) is further capped by <code>estimated input bytes / (workers × 2)</code>, never below 4 MiB. The estimate is <code>obiread::estimated_decompressed_len</code>: the file length, ×3 when the magic bytes say gzip (≈ 2.8 measured on FASTQ), ×4 for bzip2/xz/zstd — a deliberately rough figure, detected from the magic bytes, not the extension. For stdin, URLs or unreadable files the size is unknown and the memory-derived size stands. An explicit <code>--chunk-size</code> still wins.</p>
<p>Measured (2 × 48 MB reads, 16 cores, AC power, outputs identical): single-genome index, 354 M kmers — default chunk 256 MiB → 4 MiB: <strong>11.4 s → 2.4 s</strong> (−79 %), CPU 22.3 → 26 s (+17 %), peak footprint 1.44 → 0.75 GB. On the 91-genome index the memory-derived size was already 4 MiB (overhead factor 4 + 8 × 91), so nothing changes there (5.1–5.7 s either way). Not measured: a large input (≈ 1 GB gz, whose estimate gives ≈ 95 MiB chunks instead of 256 MiB: more, smaller chunks, expected lower memory).</p>