build member tables of instantiated classes/interfaces lazily - #64475
Draft
Max Schwenk (maschwenk) wants to merge 7 commits into
Draft
Max Schwenk (maschwenk) wants to merge 7 commits into
Max Schwenk (maschwenk) wants to merge 7 commits into
Conversation
Looking up one property of an instantiated class or interface reference (`expect(x).toBe`, `schema.optional`, `arr.map`) resolved all of its members: every declared member was instantiated and every inherited member merged, although most of those symbols are never used. The first lookup on such a reference now prepares a lazy member table instead. Preparing does everything resolveObjectTypeMembers does except create the member symbols, in the same order, so everything that is resolved along the way (signatures, index infos, base types and their members) is resolved exactly as before. It also records which declared members instantiateSymbol would return as they are at that point, since that depends on what has been resolved. Lookups then instantiate only the requested member, walking the prepared base types in addInheritedMembers order, and resolving the members in full later reuses the symbols already handed out. If preparing leads back to the reference, it exposes the same partial members resolveObjectTypeMembers would, and is resolved in full from then on. A lookup of a missing name answers the Object/Function augmentation from the number of call and construct signatures, counted from the declared signatures and those of the prepared base types. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bers isWeakType, getSingleSignature, getSignaturesOfStructuredType, getIndexInfosOfStructuredType, isEmptyObjectType, isFunctionObjectType and isStringIndexSignatureOnlyType resolved all members of an instantiated class or interface reference just to count its properties, signatures or index infos, or to see whether its properties are optional. For a reference with a lazy member table these are now answered from the table. Signatures are counted from the instantiated declared signatures and those of the prepared base types. Whether there are properties, and whether all of them are optional, follows from the declared members (which have the same flags as their instantiations) and the properties of the base types, merged as in addInheritedMembers. Index infos are merged from the instantiated declared index infos and those of the base types, as in resolveObjectTypeMembers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 27, 2026
Resolving the members of a lazily prepared reference in full stored every instantiated member in the table's memo, which is discarded right after, and checked each member against the list of members that instantiate to themselves with a linear scan. The list is now sorted and binary searched, and members are only memoized when looked up individually. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Property and index info lookups are hot, and nearly always see types whose members are resolved. They now check that inline before calling into the lazy member table code, which on material-ui's docs project took 2-3% of check time on its own. The lazy part of getPropertyOfTypeEx moves to getPropertyOfObjectTypeLazily. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each shape check (isWeakType, getSingleSignature, isStringIndexSignatureOnlyType, isFunctionObjectType, getPropertyOfTypeEx) had a second, lazy version of its condition. Now the lazy table stores the reference's full signatures and index infos, inherited through a helper resolveObjectTypeMembers shares, and getSignaturesOfStructuredType and getIndexInfosOfStructuredType answer from it. The checks read through those accessors and getMemberOfStructuredType, hasPropertiesOfStructuredType and everyPropertyOfStructuredType, so each condition is written once. The separate shape summary goes away, as do the hooks in getPropertyOfObjectType and isEmptyObjectType, which saved no memory, and the code moves into checker.go. This also removes a crash path: isWeakType read the table's shape, called getIndexInfosOfStructuredType, and read the shape again, which would find no table if that call had resolved the type in full. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
|
Max Schwenk (@maschwenk) I definitely want to land #64499, really nice savings from that one. Once it is in, let's see how much extra savings we can get from this one. I'm a bit concerned with adding ~500 lines of code to member resolution. |
resolveObjectTypeMembers no longer exposes a type's declared members while its base types resolve, so the lazy table doesn't need to either. A table is now either being prepared, during which the type resolves its members as usual, or ready; the materialized state, the count of inherited base types and the partial lookup paths go away. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #64474 (#64499 fixed the intersection half)
looking up one property on an instantiated class or interface builds the whole member table right now. every declared member gets instantiated and every inherited one gets merged in, even though most of them never get used. a few shape checks (
isWeakType,getSingleSignature,isStringIndexSignatureOnlyType,isFunctionObjectType) do the same thing just to count stuffthis gives such a reference a lazy member table instead. setting it up does what
resolveObjectTypeMembersdoes in the same order, except creating the member symbols. signatures and index infos get instantiated and inherited as usual, through a helperresolveObjectTypeMembersnow shares, sogetSignaturesOfStructuredTypeandgetIndexInfosOfStructuredTypecan answer from the table. member lookups only instantiate the member that was asked for, and if the full table gets built later it reuses whatever was already handed out, so symbol identity doesnt changethe shape checks read through those accessors plus
getMemberOfStructuredType,hasPropertiesOfStructuredTypeandeveryPropertyOfStructuredType, so each check is still written once. the lazy lookups alone dont save anything since the shape checks would build the full table right away, those are what make it pay offwhether
instantiateSymbolhands back the original symbol depends on what's been resolved so far, so the table records that when it's set up. with #64372 in, that's the only thing it has to copy. while a table is being set up the type just resolves its members the normal wayhistory: the first version (up to af2719b) had a separate lazy copy of each shape check, cdac4e3 reworked it to go through the accessors, and after merging main 39ce30c drops the half built member handling #64372 made unnecessary. its +344/−37 in checker.go now (was ~570), the rest of the diff is two tests and their baselines
this PR vs main at 0681ef7 (so with #64372 and #64499), typescript-benchmarking, median of 3:
on our 37k-file program, also on 0681ef7: heap 19.1 → 15.4 GiB with 4 checkers (−19%) and 12.6 → 10.6 GiB single threaded (−16%), check time −7% single threaded. same diagnostics on every run. raw results and scripts: https://gist.github.com/maschwenk/c83d9185c6961b6fb43d7d071ef39cf6
full go suite passes (also multiple checkers and
-race), lint and format are clean. addedinstantiatedReferenceMemberLookup.tsandinstantiatedReferenceShapeQueries.tswith baselines generated on unmodified main, so they pin that the output didnt changego test ./...intsc, same thinghereby testruns)hereby linthereby check:formatused claude code to help write this, ive reviewed it