-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Cache repeated mapper instantiations only within a single instantiation call #61535
base: main
Are you sure you want to change the base?
Cache repeated mapper instantiations only within a single instantiation call #61535
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 undefined
s.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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).