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

Avoid hasattr in hot loop in brotli decoder #906

Merged
merged 1 commit into from
Apr 19, 2020

Conversation

auscompgeek
Copy link
Contributor

hasattr has a nasty performance penalty when it returns false: in the background it is actually a try/except AttributeError. Since we know the method we want won't change, by instead caching the bound method object we can amortise the cost across an entire encoded body.

@florimondmanca florimondmanca added the perf Issues relating to performance label Apr 19, 2020
Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

Sounds good, thanks!

@florimondmanca florimondmanca merged commit 9085582 into encode:master Apr 19, 2020
@auscompgeek auscompgeek deleted the patch-1 branch April 19, 2020 08:24
@tomchristie tomchristie mentioned this pull request May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf Issues relating to performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants