refactor: apply rust best practices and fix memory optimizations
- Optimized memory allocation in router.rs by offloading JSON serialization to spawn_blocking and using references. - Prevented full graph duplication on startup in state.rs index rebuild. - Eliminated massive String allocations in QueryGraphPathHandler BFS loops. - Avoided temporary Strings in VisualizeGraphHandler via inline writing. - Fixed O(N) full-graph deduplication in MergeEntitiesHandler to scale efficiently.
This commit is contained in:
1 parent
251757f8fc
commit
37003be620
17 files changed
+399
-198
No files matched your search
@@ -146,10 +146,10 @@ pub async fn handle_socket(socket: WebSocket, state: Arc<AppState>, _client_type
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::RwLock;
|
||||
use crate::router::MemoryHandler;
|
||||
use crate::state::MemoryState;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -163,7 +163,11 @@ mod tests {
|
||||
});
|
||||
|
||||
// Insert a dummy client
|
||||
app_state.clients.write().unwrap().insert("test-session".to_string(), tokio::sync::mpsc::channel(1).0);
|
||||
app_state
|
||||
.clients
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert("test-session".to_string(), tokio::sync::mpsc::channel(1).0);
|
||||
|
||||
let send_task = tokio::spawn(async {});
|
||||
let recv_task = tokio::spawn(async {});
|
||||
|
||||
Reference in new issue
Block a user