Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Feature or enhancement
Similar togh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as non-existing attributes on types and instances.
microbenchmark on main:
python -m pyperf timeit -s 'import os' 'hasattr(os, "getenv")'.....................Mean +- std dev: 37.8 ns +- 1.5 nspython -m pyperf timeit -s 'import os' 'hasattr(os, "nothing")'.....................Mean +- std dev: 541 ns +- 16 nsAs ingh-92216, the reason for the slowness is time spent in creating anAttributeError, which is not needed.
By adding a special case for modules (similar to the type special case ingh-99979), this overhead can be eliminated.