perf(agent): use HashSet for eviction ID membership checks in consolidation

records.retain(|r| !evict_ids.contains(&r.id)) called Vec::contains
(linear scan) for every record against evict_ids, giving O(n·m) cost
on both Working- and Episodic-tier eviction every consolidation tick.
Build evict_ids as a HashSet for O(1) membership checks.

INT-15
This commit is contained in:
ClawHDF5 Coding Agent
2026-08-17 00:29:03 +00:00
parent d787ac04c8
commit 603fcf8757
+2 -2
View File
@@ -280,7 +280,7 @@ impl ConsolidationEngine {
if working_count > capacity {
let evict_n = working_count - capacity;
// Collect the ids of the records to evict (lowest decay = first in sorted list).
let evict_ids: Vec<u64> = working_indices[..evict_n]
let evict_ids: std::collections::HashSet<u64> = working_indices[..evict_n]
.iter()
.map(|&i| self.records[i].id)
.collect();
@@ -341,7 +341,7 @@ impl ConsolidationEngine {
});
let evict_n = episodic_count - episodic_capacity;
let evict_ids: Vec<u64> = episodic_indices[..evict_n]
let evict_ids: std::collections::HashSet<u64> = episodic_indices[..evict_n]
.iter()
.map(|&i| self.records[i].id)
.collect();