improve compiler performance on dot fields after #24005 #24074
Merged
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.
I noticed after #24005 the auto-reported boot time in PRs increased from around 8 seconds to 8.8 seconds, but I wasn't sure what could cause a performance problem that made the compiler itself compile slower, most of the changes were related to
static
which the compiler code doesn't use too often. So I figured it was unrelated.However there is still a performance problem with the changes to
tryReadingGenericParam
. If an expression likea.b
doesn't match any of the default dot field behavior (for example, is actually a callb(a)
), the compiler does a final check to see ifb
is a generic parameter ofa
. Since #24005, if the type ofa
is nottyGenericInst
or an old concept type, the compiler does a full traversal of the type ofa
to see if it contains a generic type, only then checking forc.inGenericContext > 0
to not returnnil
. This happens on every dot call.Instead, we now check for
c.inGenericContext > 0
first, only then checking if it contains a generic type, saving performance by virtue ofc.inGenericContext > 0
being both cheap and less commonly true. ThecontainsGenericType
could also be swapped out for more generic type kind checks, but I think this is incorrect even if it might pass CI.