Skip to content

Micro-optimize chained plugin #19464

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

Merged
merged 1 commit into from
Jul 17, 2025
Merged

Micro-optimize chained plugin #19464

merged 1 commit into from
Jul 17, 2025

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 16, 2025

Avoid using lambdas in the most expensive hooks, since they are slower than direct method calls. Also use if hook is None checks instead of if hook, since the prior is more efficient when compiled.

I used trace logging to look for generic/unoptimized function calls, and it was clear that ChainedPlugin was doing many unoptimized calls that were easy to avoid.

This duplicates some code, but I think it's fine since this code is updated very rarely but the code paths are very hot.

This is a part of a set of micro-optimizations that improve self check performance by ~5.5%.

Avoid using lambdas in the most expensive hooks, since they are slower
than direct method calls. Also use `if hook is None` checks instead of
`if hook`, since the prior is more efficient when compiled.

I used trace logging to look for generic/unoptimized function calls,
and it was clear that ChainedPlugin was doing many unoptimized calls
that were easy to avoid.

This is a part of a set of micro-optimizations that improve self check
performance by ~5.5%.
@JukkaL JukkaL requested a review from ilevkivskyi July 16, 2025 13:23
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@sterliakov sterliakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected that get_function_hook is similarly hot too, that probably depends on the codebase (more of OOP of more of a functional style). Would it make sense to inline it too?

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 17, 2025

Would it make sense to inline it too?

It didn't come up much in my use case, but it's true that it could be a bottleneck in other use cases. I'll do it in a follow-up PR.

@JukkaL JukkaL merged commit a82948b into master Jul 17, 2025
20 checks passed
@JukkaL JukkaL deleted the opt-6 branch July 17, 2025 09:12
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy