spillover is a generic Rust library for building external (disk-spilling) sort pipelines, with an explicit in-memory alternative for inputs that fit.
The core crate is intentionally unopinionated: it knows how to spill sorted runs to disk and merge them back, but leaves domain behavior to user-provided traits. You can plug in your own implementations for:
- sort key extraction (
SortKey) or complete record ordering - comparison (
Compare) - run reading (
DecodeRunorCodec/KeyedCodec) and writing (EncodeRun/EncodeKeyedRun) - post-merge adjacent deduplication (
AdjacentDeduplicator) - in-memory chunk sorting strategy (
ChunkSorter) - flush strategy (byte-based or item-count based budgets)
spillover-bio builds on spillover with genomics-focused defaults and convenience APIs. It uses dryice for temporary on-disk storage, includes packed sequence keys for keyed merge acceleration, provides FASTQ/FASTA-friendly record handling, and includes practical sort orders (sequence, quality tiebreaking, name, length, reverse order).
That said, spillover-bio is still extensible: users can configure dryice encodings, sort orders, built-in deduplication modes, and flush controls. When you need full control, you can always drop down to spillover directly.
Here is a small spillover-bio quickstart:
use spillover_bio::{Builder, DryIceCodec, SeqRecord};
fn rec(name: &str, seq: &str, qual: &str) -> SeqRecord {
SeqRecord::new(
name.as_bytes(),
seq.as_bytes(),
qual.as_bytes(),
)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut sorter = Builder::new()
.sort_by_illumina()
.codec(DryIceCodec::new())
.max_buffer_items(2)
.build();
for record in [
rec("r1", "TTTTTTTT", "IIIIIIII"),
rec("r2", "AAAAAAAA", "!!!!!!!!"),
rec("r3", "CCCCCCCC", "########"),
] {
sorter.push(record)?;
}
let sorted: Vec<SeqRecord> = sorter.finish()?.collect::<Result<Vec<_>, _>>()?;
assert_eq!(sorted[0].sequence(), b"AAAAAAAA");
assert_eq!(sorted[1].sequence(), b"CCCCCCCC");
assert_eq!(sorted[2].sequence(), b"TTTTTTTT");
Ok(())
}Further runnable examples:
spillover:spillover/examples/README.mdspillover-bio:spillover-bio/examples/README.md
cargo add spillover
# or
cargo add spillover-bio- If you want a ready-to-use genomics pipeline, start with
spillover-bio. - If you need a custom domain pipeline, start with
spilloverand provide ordering plus run-reading and run-writing implementations. - Use small buffer budgets in development to force spills and validate merge behavior early.
You can run examples from this workspace root:
cargo run -p spillover --example 01_basic_u64_sort
cargo run -p spillover-bio --example 01_illumina_quickstartThis repository uses mise for its development toolchain and task runner. Git is also required to fetch the read-only reference repositories used during development.
mise trust
mise install
mise run setup
mise tasks
mise run checkAt a high level, the disk-spilling pipeline in both crates follows these steps:
- collect records into an in-memory buffer
- sort the buffer using the selected key/comparator/chunk sorter
- spill sorted runs to temporary files when flush budget is reached
- merge runs with bounded fan-in
- optionally apply post-merge deduplication
Put another way, in spillover, sorting is an engine with interchangeable parts:
- Define ordering with a
SortKey/Comparepair or a complete record order; keyed complete orders also implementKeyedOrderfor stored-key comparison.ChunkSorterselects the in-memory sorting algorithm. - Define temporary-run reading with
DecodeRunfor ordinary owned-record iterators, orCodec/KeyedCodecfor lower-level control; define writing withEncodeRun/EncodeKeyedRun. - Define adjacent duplicate matching with
AdjacentDeduplicator. - Control spilling with byte budgets (
measured_budget) or item limits (max_buffer_items); these are not hard limits on total process memory.
Three practical mental models help when designing a pipeline:
- Sort semantics are a contract. Your configured order must capture the order your downstream logic depends on, including stored-key comparisons and record tie-breaking.
- Disk format is a performance lever. Better temporary encodings and keyed merge support can significantly reduce merge-time work.
- Memory limits are part of correctness. Budgets are not tuning afterthoughts; they define when data spills and therefore how the algorithm behaves at scale.
spillover-bio adds domain-specific defaults around that pipeline: sequence-aware sort orders (with quality tie-breaking), dryice-backed codecs, keyed merge acceleration, and convenience builders for common genomics workflows.
If this project helps your work, please cite the repository and crate versions you used: