-
-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Slow inspect.getmodule #92041
Comments
Looking at the test data, we see Even the typical case performs poorly - 187 modules and 8 frame call stack takes almost 2 milliseconds. Note this is with code pasted into REPL, so all the frames are within uncached moduleless frames (the worst case) #92042 reduces duration using simple caching to avoid recursion and repeated Here is before & after, running test from a file instead of REPL (a more typical use case)
(updated to show test with |
Simply having the moduleless REPL frames somewhere in the stack has a profound effect on times:
(updated to show test with |
haven't tracked down the exact tracebacks that are being processed but this led to a huge slowdown for us at sentry moving from python 3.10 to python 3.11 in one worker type this went from |
inspect has a performance problem python/cpython#92041 We now avoid calling inspect unless we are going to log
* Avoid expensive inspect calls in config validators inspect has a performance problem python/cpython#92041 We now avoid calling inspect unless we are going to log * remove unused * reduce * get_integration_logger
* Avoid expensive inspect calls in config validators inspect has a performance problem python/cpython#92041 We now avoid calling inspect unless we are going to log * remove unused * reduce * get_integration_logger
This is same solution we have in system_log Inspecting the stack got a lot more expensive in python 3.11 see python/cpython#92041 see getsentry/sentry#63965
…platforms I removed the attempt to import modules from the scene path since there are none and importlib is quite expensive trying to import modules that do not exist because of python/cpython#92041
Bug report
inspect.getmodule
is slow. It becomes slower aslen(sys.modules)
grows. It is slower with modules that don't resolve to valid file paths. This causesinspect.stack
and others to be slow as well.Tables show time in milliseconds for a single
inspect.stack()
call.Rows show
len(sys.modules)
Columns indicate stack depth
Your environment
The text was updated successfully, but these errors were encountered: