-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Wrap parse_mimetype in an lru_cache #3341
Conversation
@@ -237,6 +237,7 @@ class MimeType: | |||
parameters = attr.ib(type=MultiDict) # type: MultiDict[str] | |||
|
|||
|
|||
@functools.lru_cache(maxsize=56) |
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.
Nice idea. But why 56?
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.
No particular reason. It's potentially controlled by an attacker, so it cannot be too high. Could make it 100?
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.
There 75 mime types in nginx default mime.types file. Quite much of them are not common / popular. I'm pretty sure that 10 will be more than enough.
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.
This does include the charset
as well, so maybe 10 might be too low? There isn't much harm in having it higher, if it's too low it defeats the entire point and just adds a bit of overhead however.
Codecov Report
@@ Coverage Diff @@
## master #3341 +/- ##
==========================================
- Coverage 98.03% 97.99% -0.04%
==========================================
Files 44 44
Lines 8039 8039
Branches 1357 1357
==========================================
- Hits 7881 7878 -3
- Misses 65 67 +2
- Partials 93 94 +1
Continue to review full report at Codecov.
|
I'm curious what is the performance boost? |
Master:
This patch:
|
Ahh, one small thing: the Not sure if this is a breaking change, but the speedup is pretty nice if we can accept this. |
thanks |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
What do these changes do?
parse_mimetype
seems like an ideal candidate for anlru_cache
. The return result is immutable, it's non-trivial, called fairly often and has a single, immutable input.Are there changes in behavior for the user?
Nope.
Related issue number
None.
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.