-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Use ThinVec
for sub segments in PlaceExpr
#19470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fn sub_segments_size(segments: &thin_vec::ThinVec<PlaceExprSubSegment>) -> usize { | ||
segments.capacity() * std::mem::size_of::<PlaceExprSubSegment>() | ||
+ segments | ||
.iter() | ||
.map(|segment| segment.get_heap_size()) | ||
.sum::<usize>() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already PRd (and it's merged but not yet released) adding thin_vec
support to the getsize crate
|
|
@@ -775,7 +786,7 @@ impl std::fmt::Debug for PlaceTable { | |||
pub(super) struct PlaceTableBuilder { | |||
table: PlaceTable, | |||
|
|||
associated_place_ids: IndexVec<ScopedPlaceId, Vec<ScopedPlaceId>>, | |||
associated_place_ids: IndexVec<ScopedPlaceId, SmallVec<[ScopedPlaceId; 4]>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This SmallVec
here is "free" as 4 ScopedPlaceId
s + the tag fit into 24 bytes
Nice, looks like this yields some small speedups too! https://codspeed.io/astral-sh/ruff/branches/micha%2Fplace-table-thin-vec?runnerMode=Instrumentation |
I think |
This, unfortunately, doesn't help because An alternative to what I've done here is to split
I suspect that this might be slightly larger refactor but it might also help to untangle some of the complexity in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Yes, I thought about this when reviewing the PR that added |
I'll try to find time to look into this because it might allow us to reduce memory usage even more by changing the |
I think this would be a very nice refactor but it's also not trivial. I started and I've currently 188 errors... and many of them aren't very trivial to fix. I do think that it would help clarify many things and having separate types for |
The main blocker here is that We could split the hash map but there's little value in that because the main motivation is to reduce the size of |
* main: [ty] Use `ThinVec` for sub segments in `PlaceExpr` (#19470) [ty] Splat variadic arguments into parameter list (#18996) [`flake8-pyi`] Skip fix if all `Union` members are `None` (`PYI016`) (#19416) Skip notebook with errors in ecosystem check (#19491) [ty] Consistent use of American english (in rules) (#19488) [ty] Support iterating over enums (#19486) Fix panic for illegal `Literal[…]` annotations with inner subscript expressions (#19489) Move fix suggestion to subdiagnostic (#19464) [ty] Implement non-stdlib stub mapping for classes and functions (#19471) [ty] Disallow illegal uses of `ClassVar` (#19483) [ty] Disallow `Final` in function parameter/return-type annotations (#19480) [ty] Extend `Final` test suite (#19476) [ty] Minor change to diagnostic message for invalid Literal uses (#19482) [ty] Detect illegal non-enum attribute accesses in Literal annotation (#19477) [ty] Reduce size of `TypeInference` (#19435) Run MD tests for Markdown-only changes (#19479) Revert "[ty] Detect illegal non-enum attribute accesses in Literal annotation" [ty] Detect illegal non-enum attribute accesses in Literal annotation [ty] Added semantic token support for more identifiers (#19473) [ty] Make tuple subclass constructors sound (#19469)
* main: (28 commits) [ty] highlight the argument in `static_assert` error messages (astral-sh#19426) [ty] Infer single-valuedness for enums based on `int`/`str` (astral-sh#19510) [ty] Restructure submodule query around `File` dependency [ty] Make `Module` a Salsa ingredient [ty] Reachability analysis for `isinstance(…)` branches (astral-sh#19503) [ty] Normalize single-member enums to their instance type (astral-sh#19502) [ty] Invert `ty_ide` and `ty_project` dependency (astral-sh#19501) [ty] Implement mock language server for testing (astral-sh#19391) [ty] Detect enums if metaclass is a subtype of EnumType/EnumMeta (astral-sh#19481) [ty] perform type narrowing for places marked `global` too (astral-sh#19381) [ty] Use `ThinVec` for sub segments in `PlaceExpr` (astral-sh#19470) [ty] Splat variadic arguments into parameter list (astral-sh#18996) [`flake8-pyi`] Skip fix if all `Union` members are `None` (`PYI016`) (astral-sh#19416) Skip notebook with errors in ecosystem check (astral-sh#19491) [ty] Consistent use of American english (in rules) (astral-sh#19488) [ty] Support iterating over enums (astral-sh#19486) Fix panic for illegal `Literal[…]` annotations with inner subscript expressions (astral-sh#19489) Move fix suggestion to subdiagnostic (astral-sh#19464) [ty] Implement non-stdlib stub mapping for classes and functions (astral-sh#19471) [ty] Disallow illegal uses of `ClassVar` (astral-sh#19483) ... # Conflicts: # crates/ty_ide/src/goto.rs
Summary
This replaces the
SmallVec
onPlaceExpr
with aThinVec
. The main motivation is that many places (all symbols) have no sub segments and paying the extra cost of an empty vec (32 bytes) for each of those adds quiet a bit to overall memory usageThis reduces the
place_table
size by roughly 25%