Skip to content

Commit 01930e7

Browse files
ahaviliclaude
andcommitted
perf(l10n): optimize usages query from O(N*W) global resolution to targeted lookup (19x faster)
Replace the global resolve-all-then-filter approach with a targeted search from known records to their usages. Pre-filter candidates via HashSet membership checks on metadata keys, wrapper IDs, and wrapper names, then resolve only the small candidate set. Also fix a pre-existing wrapper-caller double-counting bug where callers already represented as owners of direct usages were listed twice, and add catalog proximity dedup for multi-catalog projects. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eec4e0f commit 01930e7

3 files changed

Lines changed: 372 additions & 72 deletions

File tree

grapha/src/app/query.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use crate::{
99
SymbolCommands, assets, cache, changes, config, fields, localization, query, render, search,
1010
};
1111

12-
use super::index::{load_graph, load_graph_for_l10n, load_graph_for_l10n_usages, open_search_index};
12+
use super::index::{
13+
load_graph, load_graph_for_l10n, load_graph_for_l10n_usages, open_search_index,
14+
};
1315

1416
fn query_cache_key(parts: &[&str]) -> String {
1517
parts.join("\0")

grapha/src/localization.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ fn build_catalog_snapshot(
294294
.trim_matches('"')
295295
.to_string(),
296296
comment: entry.comment.clone(),
297-
translations: translations_by_key
298-
.remove(&entry.id)
299-
.unwrap_or_default(),
297+
translations: translations_by_key.remove(&entry.id).unwrap_or_default(),
300298
});
301299
}
302300
}
@@ -538,7 +536,7 @@ fn closest_records(
538536
.collect()
539537
}
540538

541-
fn directory_distance(usage_file: &Path, catalog_dir: &str) -> usize {
539+
pub fn directory_distance(usage_file: &Path, catalog_dir: &str) -> usize {
542540
let usage_dir = usage_file.parent().unwrap_or_else(|| Path::new("."));
543541
let usage_components = normalized_components(usage_dir);
544542
let catalog_components = normalized_components(Path::new(catalog_dir));

0 commit comments

Comments
 (0)