[ty] Remove excess capacity from more Salsa cached collections#25411
Conversation
d83258c to
feee433
Compare
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownflake8
trio
sphinx
prefect
|
|
af6bd74 to
ad53af8
Compare
| } | ||
|
|
||
| pub(super) fn finish(mut self) -> AstIds { | ||
| self.uses_map.shrink_to_fit(); |
There was a problem hiding this comment.
This is a HashMap and we only append to it using insert.
| place_tables.shrink_to_fit(); | ||
| use_def_maps.shrink_to_fit(); | ||
| ast_ids.shrink_to_fit(); | ||
| self.definitions_by_node.shrink_to_fit(); |
There was a problem hiding this comment.
Hash map, insertion only by using entry and insert
| use_def_maps.shrink_to_fit(); | ||
| ast_ids.shrink_to_fit(); | ||
| self.definitions_by_node.shrink_to_fit(); | ||
| self.statements_by_node.shrink_to_fit(); |
There was a problem hiding this comment.
Hash map, insertion only by using insert
| self.definitions_by_node.shrink_to_fit(); | ||
| self.statements_by_node.shrink_to_fit(); | ||
| self.enclosing_lambda_statements.shrink_to_fit(); | ||
| self.collections_by_use.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, insertion with insert
| self.statements_by_node.shrink_to_fit(); | ||
| self.enclosing_lambda_statements.shrink_to_fit(); | ||
| self.collections_by_use.shrink_to_fit(); | ||
| self.uses_by_collection.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, insertion using entry
|
|
||
| self.imported_modules.shrink_to_fit(); | ||
| self.scope_ids_by_scope.shrink_to_fit(); | ||
| self.scopes_by_node.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, insertion exclusively using insert
| self.imported_modules.shrink_to_fit(); | ||
| self.scope_ids_by_scope.shrink_to_fit(); | ||
| self.scopes_by_node.shrink_to_fit(); | ||
| self.generator_functions.shrink_to_fit(); |
There was a problem hiding this comment.
Hashset, insertion exclusively using insert
| self.reachable_symbol_definitions.shrink_to_fit(); | ||
| self.reachable_member_definitions.shrink_to_fit(); | ||
| self.bindings_by_use.shrink_to_fit(); | ||
| self.multi_bindings_by_use.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, insertion with entry
| self.bindings_by_use.shrink_to_fit(); | ||
| self.multi_bindings_by_use.shrink_to_fit(); | ||
| self.range_reachability.shrink_to_fit(); | ||
| self.declarations_by_binding.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, insertion with insert
| interned_ids_by_definition.insert(definition, interned_id); | ||
| } | ||
|
|
||
| interned_ids_by_definition.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, Uses insert
| interned_ids_by_binding.insert(binding, interned_id); | ||
| } | ||
|
|
||
| interned_ids_by_binding.shrink_to_fit(); |
There was a problem hiding this comment.
HashMap, uses insert
AlexWaygood
left a comment
There was a problem hiding this comment.
This makes sense to me, though it's worth noting that the pydantic and multithreaded benchmarks are showing 1-2% regressions
| fn sorted_list(db: &dyn Db) -> Vec<Module<'_>> { | ||
| let mut modules = list_modules(db); | ||
| let mut modules = list_modules(db).to_vec(); | ||
| modules.sort_by(|m1, m2| m1.name(db).cmp(m2.name(db))); | ||
| modules | ||
| } |
There was a problem hiding this comment.
is there ever a reason for wanting an unsorted list of modules? We could consider sorting the list of modules before returning the boxed slice from the cached list_modules function, and getting rid of this additional (uncached) function
There was a problem hiding this comment.
Yes, import completions doesn't bother about sorting and all modules applies a global sorting.
350c084 to
e57cc69
Compare
Summary
This PR drops container excess capacities in more places for Salsa cached queries by using a boxed slice or calling
shrink_to_fit.This PR also removes a few unnecessary
shrink_to_fitcalls. For maps, callingshrink_to_fitis only necessary afterextending or when elements were removed. A map that was built by only usinginsertorentrynever shrinks its capacity. This helps improve performance a little.