perf: replace inefficient memory cloning vectors with fast zero-allocation read iterators

This commit is contained in:
Riz Ashraf committed 2026-09-21 12:51:26 +01:00
1 parent 5da422d23a
commit 3c31aeec1f
6 files changed
+108 -69

No files matched your search

+12 -6
View File
@@ -51,7 +51,7 @@ impl McpTool for ReadStickyNotesHandler {
}
async fn execute(&self, _args: Value, state: Arc<MemoryState>) -> Result<String, String> {
let data = serde_json::to_string(&state.sticky.read()).unwrap_or_else(|_| "[]".to_string());
let data = state.sticky.read_with(|s| serde_json::to_string(s).unwrap_or_else(|_| "[]".to_string()));
Ok(data.to_string())
}
}
@@ -161,11 +161,16 @@ impl McpTool for ReadHandoffMemosHandler {
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
let req: ReadHandoffMemosTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
let mut items = state.handoff_memos.read();
if let Some(ns) = req.namespace {
items.retain(|i| i.namespace == ns);
}
let data = serde_json::to_string(&items).unwrap_or_default();
let data = state.handoff_memos.read_with(|items| {
let filtered: Vec<_> = items.iter().filter(|i| {
if let Some(ns) = &req.namespace {
&i.namespace == ns
} else {
true
}
}).collect();
serde_json::to_string(&filtered).unwrap_or_default()
});
Ok(data.to_string())
}
}
@@ -271,3 +276,4 @@ impl McpTool for GenerateStandupReportHandler {
Ok(report.to_string())
}
}