Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/commands/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ struct ClipProcessedBatch {

impl MemoryEstimate for ClipProcessedBatch {
fn estimate_heap_size(&self) -> usize {
self.clipped_records.iter().map(MemoryEstimate::estimate_heap_size).sum()
self.clipped_records.iter().map(MemoryEstimate::estimate_heap_size).sum::<usize>()
+ self.clipped_records.capacity() * std::mem::size_of::<RecordBuf>()
}
}

Expand Down Expand Up @@ -2462,4 +2463,29 @@ mod tests {

Ok(())
}

#[test]
fn test_clip_processed_batch_memory_estimate() {
use fgumi_lib::sam::builder::RecordBuilder;
use noodles::sam::alignment::record_buf::RecordBuf;

let record = RecordBuilder::new().sequence("ACGT").qualities(&[30, 30, 30, 30]).build();
let mut records = Vec::with_capacity(10);
records.push(record);

let batch = ClipProcessedBatch {
clipped_records: records,
templates_count: 1,
overlap_clipped_count: 0,
extend_clipped_count: 0,
};

let estimate = batch.estimate_heap_size();
// Should include Vec overhead for capacity * size_of::<RecordBuf>()
let vec_overhead = 10 * std::mem::size_of::<RecordBuf>();
assert!(
estimate >= vec_overhead,
"estimate {estimate} should include Vec<RecordBuf> overhead {vec_overhead}"
);
}
}
23 changes: 22 additions & 1 deletion src/commands/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ struct CodecProcessedBatch {

impl MemoryEstimate for CodecProcessedBatch {
fn estimate_heap_size(&self) -> usize {
self.consensus_output.data.len() + self.rejects.iter().map(Vec::len).sum::<usize>()
self.consensus_output.data.capacity()
+ self.rejects.iter().map(Vec::capacity).sum::<usize>()
+ self.rejects.capacity() * std::mem::size_of::<Vec<u8>>()
}
}

Expand Down Expand Up @@ -1185,4 +1187,23 @@ mod tests {

Ok(())
}

#[test]
fn test_codec_processed_batch_memory_estimate() {
let mut data = Vec::with_capacity(1024);
data.extend_from_slice(&[0u8; 100]);
let mut reject = Vec::with_capacity(512);
reject.extend_from_slice(&[0u8; 50]);

let batch = CodecProcessedBatch {
consensus_output: ConsensusOutput { data, count: 1 },
rejects: vec![reject],
groups_count: 1,
stats: CodecConsensusStats::default(),
};

let estimate = batch.estimate_heap_size();
assert!(estimate >= 1024 + 512, "estimate {estimate} should be >= 1536 (capacities)");
assert!(estimate > 1024 + 512, "estimate {estimate} should include Vec overhead");
}
}
23 changes: 23 additions & 0 deletions src/commands/dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl BatchWeight for ProcessedDedupGroup {
impl MemoryEstimate for ProcessedDedupGroup {
fn estimate_heap_size(&self) -> usize {
self.templates.iter().map(MemoryEstimate::estimate_heap_size).sum::<usize>()
+ self.templates.capacity() * std::mem::size_of::<Template>()
+ self.family_sizes.capacity() * std::mem::size_of::<(usize, u64)>()
+ std::mem::size_of::<DedupMetrics>()
}
Expand Down Expand Up @@ -2805,4 +2806,26 @@ mod tests {
bam_fields::set_flags(&mut rec, flags_with_dup & !bam_fields::flags::DUPLICATE);
assert_eq!(bam_fields::flags(&rec) & bam_fields::flags::DUPLICATE, 0);
}

#[test]
fn test_processed_dedup_group_memory_estimate() {
let template = create_test_template("test", &[30, 30, 30, 30]);
let mut templates = Vec::with_capacity(10);
templates.push(template);

let batch = ProcessedDedupGroup {
templates,
family_sizes: AHashMap::new(),
dedup_metrics: DedupMetrics::default(),
input_record_count: 1,
};

let estimate = batch.estimate_heap_size();
// Should include Vec<Template> overhead for capacity * size_of::<Template>()
let vec_overhead = 10 * std::mem::size_of::<Template>();
assert!(
estimate >= vec_overhead,
"estimate {estimate} should include Vec<Template> overhead {vec_overhead}"
);
}
}
24 changes: 23 additions & 1 deletion src/commands/duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ struct DuplexProcessedBatch {

impl MemoryEstimate for DuplexProcessedBatch {
fn estimate_heap_size(&self) -> usize {
self.consensus_output.data.len() + self.rejects.iter().map(Vec::len).sum::<usize>()
self.consensus_output.data.capacity()
+ self.rejects.iter().map(Vec::capacity).sum::<usize>()
+ self.rejects.capacity() * std::mem::size_of::<Vec<u8>>()
}
}

Expand Down Expand Up @@ -1621,4 +1623,24 @@ mod tests {

Ok(())
}

#[test]
fn test_duplex_processed_batch_memory_estimate() {
let mut data = Vec::with_capacity(1024);
data.extend_from_slice(&[0u8; 100]);
let mut reject = Vec::with_capacity(512);
reject.extend_from_slice(&[0u8; 50]);

let batch = DuplexProcessedBatch {
consensus_output: ConsensusOutput { data, count: 1 },
rejects: vec![reject],
groups_count: 1,
stats: ConsensusCallingStats::default(),
overlapping_stats: None,
};

let estimate = batch.estimate_heap_size();
assert!(estimate >= 1024 + 512, "estimate {estimate} should be >= 1536 (capacities)");
assert!(estimate > 1024 + 512, "estimate {estimate} should include Vec overhead");
}
}
Loading
Loading