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
e24f71a64f
2 files changed
+13
-10
No files matched your search
@@ -39,3 +39,8 @@ tempfile = "3.27.0"
|
|||||||
[[bin]]
|
[[bin]]
|
||||||
name = "test_rmcp"
|
name = "test_rmcp"
|
||||||
path = "src/bin_test.rs"
|
path = "src/bin_test.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "bin_test_axum"
|
||||||
|
path = "src/bin_test_axum.rs"
|
||||||
|
|
||||||
+8
-10
@@ -297,8 +297,8 @@ async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::E
|
|||||||
get({
|
get({
|
||||||
let state_clone = app_state.handler.state.clone();
|
let state_clone = app_state.handler.state.clone();
|
||||||
move || async move {
|
move || async move {
|
||||||
let graph = state_clone.get_full_graph();
|
let graph_json = state_clone.read_graph(|g| serde_json::to_string(g).unwrap_or_else(|_| "{}".to_string()));
|
||||||
axum::Json(graph)
|
([(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({
|
get({
|
||||||
let state_clone = app_state.handler.state.clone();
|
let state_clone = app_state.handler.state.clone();
|
||||||
move || async move {
|
move || async move {
|
||||||
let tasks = state_clone.tasks.read_with(|t| t.clone());
|
let tasks_json = state_clone.tasks.read_with(|t| serde_json::to_string(t).unwrap_or_else(|_| "[]".to_string()));
|
||||||
axum::Json(tasks)
|
([(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({
|
get({
|
||||||
let state_clone = app_state.handler.state.clone();
|
let state_clone = app_state.handler.state.clone();
|
||||||
move || async move {
|
move || async move {
|
||||||
let sticky = state_clone.sticky.read_with(|s| s.clone());
|
let sticky_json = state_clone.sticky.read_with(|s| serde_json::to_string(s).unwrap_or_else(|_| "[]".to_string()));
|
||||||
axum::Json(sticky)
|
([(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({
|
get({
|
||||||
let state_clone = app_state.handler.state.clone();
|
let state_clone = app_state.handler.state.clone();
|
||||||
move || async move {
|
move || async move {
|
||||||
let activities = state_clone.recent_activities.read_with(|a| {
|
let activities_json = state_clone.recent_activities.read_with(|a| serde_json::to_string(a).unwrap_or_else(|_| "[]".to_string()));
|
||||||
a.iter().cloned().collect::<Vec<_>>()
|
([(axum::http::header::CONTENT_TYPE, "application/json")], activities_json)
|
||||||
});
|
|
||||||
axum::Json(serde_json::json!(activities))
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user