-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Reduce size of member table #19572
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
|
|
fcd2fa4 to
51f94f0
Compare
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
88cd5f2 to
892f555
Compare
carljm
left a comment
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!
892f555 to
59bdcfa
Compare
* origin/main: [ty] Implemented support for "rename" language server feature (#19551) [ty] Reduce size of member table (#19572) [ty] Move server capabilities creation (#19798) [ty] Repurpose `FunctionType.into_bound_method_type` to return `BoundMethodType` (#19793) [ty] Validate writes to `TypedDict` keys (#19782) [ty] Add support for using the test command emitted when a mdtest fails (#19794)
* dcreager/bound-typevar: (24 commits) more comment fix this isn't true anymore fix inner function in overload implementation ecosystem error Update Rust toolchain to 1.89 (#19807) [ty] Add `ty.inlayHints.variableTypes` server option (#19780) synthetic typevars for type materializations are bound [ty] Add failing tests for tuple subclasses (#19803) [ty] Add `ty.experimental.rename` server setting (#19800) clippy make BoundTypeVarInstance interned [ty] Implemented support for "rename" language server feature (#19551) [ty] Reduce size of member table (#19572) [ty] Move server capabilities creation (#19798) separate types! tmp allow KnownInstance::TypeVar in type expressions bind typevar in Generic/Protocol base class reference [ty] Repurpose `FunctionType.into_bound_method_type` to return `BoundMethodType` (#19793) remove unneeded GenericContext::with_binding_context create KnownInstanceType::TypeVar for PEP 695 too ...
Summary
This PR shrinks the size of the members table by ~28% (from 611MB to 438MB on a large project).
This is achieved by changing how we store
MemberExpr.Before
There are a few issues with this layout:
MemberSegmentitself is 32 bytes because it stores aString(or int) for each segment. This is an issue for multiple reasons:This PR shrinks the size of
MemberExprandMemberSegmentand reduces the cases where heap allocating the segments is necessary.New
The first change is that we change
symbol_nameto a path. The path stores the entire path of the member expression. For example,a.b[4]becomesab4. This avoids the need for each segment to store its ownName(orInt)The second important change is that
Segmentsis now an enum over a small and a heap variant:SmallSegmentspacks up to 7 segments into a singleu64(see docstring for more details).SegmentInfopacks both an offset and a kind, so that a single segment only takes 4 bytes (it's au32).All these improvements together shrink
MemberExprfrom 64 bytes to 40 bytes