-
-
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
Middleware fix up is unexpectedly expensive #9196
Comments
If I take out the context manager and write it out as a simple try/finally diff --git a/aiohttp/web_middlewares.py b/aiohttp/web_middlewares.py
index 5da1533c0..e18bd4018 100644
--- a/aiohttp/web_middlewares.py
+++ b/aiohttp/web_middlewares.py
@@ -110,7 +110,12 @@ def normalize_path_middleware(
def _fix_request_current_app(app: "Application") -> Middleware:
@middleware
async def impl(request: Request, handler: Handler) -> StreamResponse:
- with request.match_info.set_current_app(app):
+ match_info = request.match_info
+ prev = match_info._current_app
+ match_info._current_app = app
+ try:
return await handler(request)
+ finally:
+ match_info._current_app = prev
return impl before
after
|
The context manager is 8% of the run time... thats very unexpected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aiohttp/aiohttp/web_middlewares.py
Line 116 in f95bcaf
it’s likely the contextmanager decorator but need to dig in more
The text was updated successfully, but these errors were encountered: