Skip to content
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

improve compiler performance on dot fields after #24005 #24074

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Sep 7, 2024

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 like a.b doesn't match any of the default dot field behavior (for example, is actually a call b(a)), the compiler does a final check to see if b is a generic parameter of a. Since #24005, if the type of a is not tyGenericInst or an old concept type, the compiler does a full traversal of the type of a to see if it contains a generic type, only then checking for c.inGenericContext > 0 to not return nil. 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 of c.inGenericContext > 0 being both cheap and less commonly true. The containsGenericType could also be swapped out for more generic type kind checks, but I think this is incorrect even if it might pass CI.

@Araq Araq merged commit ebcfd96 into nim-lang:devel Sep 8, 2024
17 of 19 checks passed
Copy link
Contributor

github-actions bot commented Sep 8, 2024

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from ebcfd96

Hint: mm: orc; opt: speed; options: -d:release
174154 lines; 8.231s; 655.215MiB peakmem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants