Add execution timing and parallelize sibling stats

Instruments the phylo command pipeline with structured execution timing, wrapping major computational blocks with stage hooks and printing aggregated metrics upon completion. Additionally, parallelizes sibling counting logic using Rayon to process independent layer directories concurrently, preserving identical functionality and public API contracts.
This commit is contained in:
Eric Coissac
2026-08-16 20:53:22 +02:00
parent 32d6720f50
commit c990087ef3
2 changed files with 63 additions and 13 deletions
+32 -13
View File
@@ -1,5 +1,7 @@
use std::sync::Arc;
use rayon::prelude::*;
use obicompactvec::SiblingAnnex;
use obikpartitionner::KmerPartition;
use obisys::progress_bar;
@@ -68,19 +70,36 @@ impl SiblingStatsExt for KmerIndex {
fn sibling_family_size_histogram(&self) -> OKIResult<[u64; 4]> {
let layer_dirs = super::family_scan::sibling_layer_dirs(self)?;
let mut counts = [0u64; 4];
for layer_dir in &layer_dirs {
let annex = SiblingAnnex::open(&layer_dir.join(ANNEX_FILE_NAME))?;
for slot in 0..annex.len() {
let Some(mask) = annex.get(slot) else { continue };
if !mask.is_minorant() {
continue; // family tallied once, at its minorant
}
counts[mask.siblings() as usize] += 1;
}
}
Ok(counts)
// Each layer's annex file is independent — no shared `PartitionCache`
// and no `scan_layer_families` partition-grouped locality to protect
// (unlike `sibling_annex_stats`/`distance`/`cardinality_tally`), so
// layers can be scanned concurrently.
layer_dirs
.par_iter()
.try_fold(
|| [0u64; 4],
|mut counts, layer_dir| -> OKIResult<[u64; 4]> {
let annex = SiblingAnnex::open(&layer_dir.join(ANNEX_FILE_NAME))?;
for slot in 0..annex.len() {
let Some(mask) = annex.get(slot) else { continue };
if !mask.is_minorant() {
continue; // family tallied once, at its minorant
}
counts[mask.siblings() as usize] += 1;
}
Ok(counts)
},
)
.try_reduce(
|| [0u64; 4],
|a, b| {
let mut sum = a;
for i in 0..4 {
sum[i] += b[i];
}
Ok(sum)
},
)
}
fn sibling_annex_stats(&self) -> OKIResult<SiblingAnnexStats> {