mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-28 10:29:30 +02:00
perf: pre-allocate collections with known capacity in hot paths
- Use with_capacity for chunk_by_source, results, per_entity_traces, and selected_chunks in assemble() where bound is known - Pre-allocate tokens/terms vectors in normalize_fts_query and extract_keywords based on input length - Pre-allocate neighbor_ids, seen, and ordered in graph expansion based on relationship count
This commit is contained in:
@@ -44,8 +44,8 @@ pub async fn find_entities_by_relationship_by_id(
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let mut neighbor_ids: Vec<String> = Vec::new();
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
let mut neighbor_ids: Vec<String> = Vec::with_capacity(relationships.len());
|
||||
let mut seen: HashSet<String> = HashSet::with_capacity(relationships.len());
|
||||
for rel in relationships {
|
||||
if rel.in_ == entity_id {
|
||||
if seen.insert(rel.out.clone()) {
|
||||
@@ -97,7 +97,7 @@ pub async fn find_entities_by_relationship_by_id(
|
||||
.map(|entity| (entity.id.clone(), entity))
|
||||
.collect();
|
||||
|
||||
let mut ordered = Vec::new();
|
||||
let mut ordered = Vec::with_capacity(neighbor_ids.len());
|
||||
for id in neighbor_ids {
|
||||
if let Some(entity) = neighbor_map.remove(&id) {
|
||||
ordered.push(entity);
|
||||
|
||||
Reference in New Issue
Block a user