From 1f6a87f7701c9513045d05d29b4e999ce136d0fd Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 16 Jan 2026 13:22:15 -0500 Subject: [PATCH] [ty] Optimize collection of "all symbols" Instead of locking and unlocking the mutex for every symbol, we gather what we can and only lock the mutex after processing a module. Before: ``` $ ./target/profiling/ty_completion_bench ~/astral/relatedclones/scratch-home-assistant/homeassistant/scratch.py 1 -q --iters 30 total elapsed for initial completions request: 579.057075ms total elapsed: 5.627666455s, time per completion request: 187.588881ms ``` After: ``` $ ./target/profiling/ty_completion_bench ~/astral/relatedclones/scratch-home-assistant/homeassistant/scratch.py 1 -q --iters 30 total elapsed for initial completions request: 565.911487ms total elapsed: 5.254306446s, time per completion request: 175.143548ms ``` This is a very naive/simplistic "improvement." We can probably do better. --- crates/ty_ide/src/all_symbols.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/ty_ide/src/all_symbols.rs b/crates/ty_ide/src/all_symbols.rs index bdc6c54b69..d2e4ce0ba4 100644 --- a/crates/ty_ide/src/all_symbols.rs +++ b/crates/ty_ide/src/all_symbols.rs @@ -72,22 +72,19 @@ pub fn all_symbols<'db>( ); let _entered = symbols_for_file_span.entered(); + let mut symbols = vec![]; if query.is_match_symbol_name(module.name(&*db)) { - let symbol = AllSymbolInfo::from_module(&*db, module, file); - results.lock().unwrap().push(symbol); + symbols.push(AllSymbolInfo::from_module(&*db, module, file)); } for (_, symbol) in symbols_for_file_global_only(&*db, file).search(query) { - let symbol = AllSymbolInfo::from_non_module_symbol( + symbols.push(AllSymbolInfo::from_non_module_symbol( &*db, symbol.to_owned(), module, file, - ); - // It seems like we could do better here than - // locking `results` for every single symbol, - // but this works pretty well as it is. - results.lock().unwrap().push(symbol); + )); } + results.lock().unwrap().extend(symbols); }); } });