-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Cache results of expensive repetitive type operations #49760
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
@typescript-bot perf test faster |
Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at cb09077. You can monitor the build here. Update: The results are in! |
@ahejlsberg Here they are:Comparison Report - main..49760
System
Hosts
Scenarios
Developer Information: |
Nice 12% improvement in check time for |
@@ -774,6 +774,7 @@ namespace ts { | |||
const stringMappingTypes = new Map<string, StringMappingType>(); | |||
const substitutionTypes = new Map<string, SubstitutionType>(); | |||
const subtypeReductionCache = new Map<string, Type[]>(); | |||
const cachedTypes = new Map<string, Type>(); |
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.
Why one cache for multiple calls rather than one per? I would have thought that would be more efficient because you don't have to make special keys (and could just use the type ids as keys) and for locality reasons, so I'm curious is there's some perf thing I'm missing.
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.
In two of the three cases we have to create composite keys anyways, so just by making sure the keys don't overlap we can share the same cache and access helpers. In the third case we could just go by type id, but would save us very little time and could add more lines of code.
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.
Ah, I missed the composite key.
Fixes #49622.