Optimize reference graph container value type for topological_sort.

Optimize initial container capacity estimates.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-02-14 10:23:47 +00:00
parent b7ea9714e8
commit 1bd4ab0601
15 changed files with 192 additions and 155 deletions

View File

@@ -1,7 +1,4 @@
use std::{
collections::{HashMap, HashSet},
iter::once,
};
use std::{collections::HashMap, iter::once};
use futures::{FutureExt, StreamExt, stream::FuturesOrdered};
use ruma::{
@@ -50,7 +47,7 @@ where
while let Some((prev_event_id, mut outlier)) = todo_outlier_stack.next().await {
let Some((pdu, mut json_opt)) = outlier.pop() else {
// Fetch and handle failed
graph.insert(prev_event_id.clone(), HashSet::new());
graph.insert(prev_event_id.clone(), Default::default());
continue;
};
@@ -59,7 +56,7 @@ where
let limit = self.services.server.config.max_fetch_prev_events;
if amount > limit {
debug_warn!(?limit, "Max prev event limit reached!");
graph.insert(prev_event_id.clone(), HashSet::new());
graph.insert(prev_event_id.clone(), Default::default());
continue;
}
@@ -74,7 +71,7 @@ where
let Some(json) = json_opt else {
// Get json failed, so this was not fetched over federation
graph.insert(prev_event_id.clone(), HashSet::new());
graph.insert(prev_event_id.clone(), Default::default());
continue;
};
@@ -104,7 +101,7 @@ where
);
} else {
// Time based check failed
graph.insert(prev_event_id.clone(), HashSet::new());
graph.insert(prev_event_id.clone(), Default::default());
}
eventid_info.insert(prev_event_id.clone(), (pdu, json));