classification
Title: Optimize repeated calls to `__import__()`
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Kronuz
Priority: normal Keywords: patch

Created on 2021-03-03 20:48 by Kronuz, last changed 2021-03-03 21:02 by Kronuz.

Pull Requests
URL Status Linked Edit
PR 24735 open Kronuz, 2021-03-03 21:02
Messages (1)
msg388057 - (view) Author: Germán Méndez Bravo (Kronuz) * Date: 2021-03-03 20:48
A call to `importlib.__import__()` normally locks the import for the module being worked on; this, however has a performance impact for modules that are already imported and fully initialized. An example of this are inline `__import__()` calls in a hot path that is called repeatedly during the life of the process.

Proposal: A two steps check in `importlib._bootstrap._find_and_load()` to avoid locking when the module has been already imported and it's ready.
History
Date User Action Args
2021-03-03 21:02:29Kronuzsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23506
2021-03-03 20:48:50Kronuzcreate