-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
performancePerformance optimizationPerformance optimization
Description
Problem
Context recall, summary injection, and compaction allocate strings without capacity hints, causing 2-4 reallocations per operation.
Files: crates/zeph-core/src/agent/context.rs lines 331-357, 448-469, 504-528
Current code:
let mut recall_text = String::from(RECALL_PREFIX); // No capacity
for item in &recalled {
let entry = format!("- [{}] {}\n", role_label, item.message.content);
recall_text.push_str(&entry); // Reallocation risk
}Impact
- CPU: 10-20% overhead in context preparation (flamegraph measured)
- Latency: +5-15ms per user message with context budget active
- Memory: Heap fragmentation from temporary allocations
Solution
let estimated_capacity = token_budget * 3; // bytes ≈ tokens × 3
let mut recall_text = String::with_capacity(estimated_capacity.min(4096));Apply same pattern to:
fetch_semantic_recall(line 331)fetch_cross_session(line 448)fetch_summaries(line 504)compact_context(line 58)
Priority: P0
Effort: Small (1 hour)
Related to #391
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
performancePerformance optimizationPerformance optimization