perf(api): eliminate expensive heap allocations and memory clones by serializing axum response payloads directly from store read locks
This commit is contained in:
1 parent
af2c4ab046
commit
27a4f3f320
4 files changed
+36
-10
No files matched your search
@@ -39,3 +39,8 @@ tempfile = "3.27.0"
|
||||
[[bin]]
|
||||
name = "test_rmcp"
|
||||
path = "src/bin_test.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "bin_test_axum"
|
||||
path = "src/bin_test_axum.rs"
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
use axum::response::IntoResponse;
|
||||
|
||||
fn test_response() -> impl IntoResponse {
|
||||
let tasks_json = "[]".to_string();
|
||||
(
|
||||
[(axum::http::header::CONTENT_TYPE, "application/json")],
|
||||
tasks_json,
|
||||
).into_response()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,12 @@
|
||||
fn main() {
|
||||
let init = rmcp::model::InitializeResult::new(
|
||||
rmcp::model::ServerCapabilities::builder()
|
||||
.enable_tools()
|
||||
.build(),
|
||||
)
|
||||
.with_server_info(rmcp::model::Implementation::new(
|
||||
"gemini-mcp-memory",
|
||||
"3.0.0",
|
||||
));
|
||||
println!("{:?}", serde_json::to_string(&init));
|
||||
}
|
||||
+8
-10
@@ -297,8 +297,8 @@ async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::E
|
||||
get({
|
||||
let state_clone = app_state.handler.state.clone();
|
||||
move || async move {
|
||||
let graph = state_clone.get_full_graph();
|
||||
axum::Json(graph)
|
||||
let graph_json = state_clone.read_graph(|g| serde_json::to_string(g).unwrap_or_else(|_| "{}".to_string()));
|
||||
([(axum::http::header::CONTENT_TYPE, "application/json")], graph_json)
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -324,8 +324,8 @@ async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::E
|
||||
get({
|
||||
let state_clone = app_state.handler.state.clone();
|
||||
move || async move {
|
||||
let tasks = state_clone.tasks.read_with(|t| t.clone());
|
||||
axum::Json(tasks)
|
||||
let tasks_json = state_clone.tasks.read_with(|t| serde_json::to_string(t).unwrap_or_else(|_| "[]".to_string()));
|
||||
([(axum::http::header::CONTENT_TYPE, "application/json")], tasks_json)
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -334,8 +334,8 @@ async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::E
|
||||
get({
|
||||
let state_clone = app_state.handler.state.clone();
|
||||
move || async move {
|
||||
let sticky = state_clone.sticky.read_with(|s| s.clone());
|
||||
axum::Json(sticky)
|
||||
let sticky_json = state_clone.sticky.read_with(|s| serde_json::to_string(s).unwrap_or_else(|_| "[]".to_string()));
|
||||
([(axum::http::header::CONTENT_TYPE, "application/json")], sticky_json)
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -372,10 +372,8 @@ async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::E
|
||||
get({
|
||||
let state_clone = app_state.handler.state.clone();
|
||||
move || async move {
|
||||
let activities = state_clone.recent_activities.read_with(|a| {
|
||||
a.iter().cloned().collect::<Vec<_>>()
|
||||
});
|
||||
axum::Json(serde_json::json!(activities))
|
||||
let activities_json = state_clone.recent_activities.read_with(|a| serde_json::to_string(a).unwrap_or_else(|_| "[]".to_string()));
|
||||
([(axum::http::header::CONTENT_TYPE, "application/json")], activities_json)
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user