Cache repeated mapper instantiations only within a single instantiation call#61535
Cache repeated mapper instantiations only within a single instantiation call#61535Andarist wants to merge 12 commits intomicrosoft:mainfrom
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
5b50238 to
82666d1
Compare
|
@typescript-bot test it |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
|
FWIW, check times for TS 5.8 This PR (#61535) at commit 82666d1: |
| if (index === -1) { | ||
| pushActiveMapper(mapper); | ||
| } | ||
| const key = type.id + getAliasId(aliasSymbol, aliasTypeArguments); | ||
| const mapperCache = activeTypeMappersCaches[index !== -1 ? index : activeTypeMappersCount - 1]; | ||
| const cached = mapperCache.get(key); | ||
| if (cached) { | ||
| return cached; | ||
| } |
There was a problem hiding this comment.
Since key and mapperCache aren't used for initial occurrences of mappers, computing the key can be avoided:
| if (index === -1) { | |
| pushActiveMapper(mapper); | |
| } | |
| const key = type.id + getAliasId(aliasSymbol, aliasTypeArguments); | |
| const mapperCache = activeTypeMappersCaches[index !== -1 ? index : activeTypeMappersCount - 1]; | |
| const cached = mapperCache.get(key); | |
| if (cached) { | |
| return cached; | |
| } | |
| let key: string | undefined; | |
| let mapperCache: Map<string, Type> | undefined; | |
| if (index === -1) { | |
| pushActiveMapper(mapper); | |
| } else { | |
| key = type.id + getAliasId(aliasSymbol, aliasTypeArguments); | |
| mapperCache = activeTypeMappersCaches[index]; | |
| const cached = mapperCache.get(key); | |
| if (cached) { | |
| return cached; | |
| } | |
| } |
Likely also needs some updates below because of the undefineds.
I also wonder if it's worth making the allocation of the Map lazy (and/or to keep it around if it's empty)
There was a problem hiding this comment.
Or possibly only push if the type could potentially recurse (depending on the type flags), although I suspect that delaying the allocation of Map should be similar in perf; the push/pop operations themselves should be rather cheap.
There was a problem hiding this comment.
Thanks for the suggestions. I'm not sure if this PR is going to make it though - so, for now, I'm refraining from making any changes to it.
|
@typescript-bot pack this |
|
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
|
I moved this to #61505 given the whole conversation is happening there anyway |
This is an alternative to #61505 , I hope this might have better memory consumption characteristics (at the expense of repeated work, the instantiations diff can be seen here).