-
-
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
Improve middleware performance #9200
base: master
Are you sure you want to change the base?
Conversation
The contextmanager in cff60eb added quite a bit of overhead and was only used for fixing the current app when using middleware. I did a github code search and did not find usage of set_current_app outside of aiohttp so I think its safe to remove as its unlikely to be used outside of aiohttp.
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #9200 +/- ##
=======================================
Coverage 98.31% 98.31%
=======================================
Files 107 107
Lines 34483 34507 +24
Branches 4093 4100 +7
=======================================
+ Hits 33901 33927 +26
+ Misses 411 410 -1
+ Partials 171 170 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Is it possibly caused by the exception handling or something? |
Yeah it looks like the |
I don't think enter is an issue. I believe But, exit handles an exception in the expected case. I can't think of any way to make that more efficient though, other than not using the decorator... |
The profile shows the most expensive part is Line 108 on cpython |
I recall we had a similar problem with rendering templates in Home Assistant (we can render many per second) and the solution was to create the context manager once and use it over and over... that worked because there was no await and everything finished synchronously, but we can't use that solution here. |
Looks to me like there's a ContextDecorator which uses _recreate_cm() to avoid redoing the init everytime. It seems to me like the decorators could be improved a little to do that same thing instead of instantiating a new class directly on every call. Not sure how much you'd get from that, but atleast would save fetching the docs attribute etc. in the init. |
What do these changes do?
The contextmanager in cff60eb added quite a bit of overhead and was only used for fixing the current app when using middleware. I did a github code search and did not find usage of
set_current_app
outside of aiohttp so I think its safe to remove as its unlikely to be used outside of aiohttp.closes #9196
Are there changes in behavior for the user?
The
set_current_app
function has been removed.Is it a substantial burden for the maintainers to support this?
no