]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-43392: Optimize repeated calls to `__import__()` (GH-24735)
authorGermán Méndez Bravo <kronuz@fb.com>
Thu, 12 Aug 2021 18:23:29 +0000 (11:23 -0700)
committerGitHub <noreply@github.com>
Thu, 12 Aug 2021 18:23:29 +0000 (11:23 -0700)
commit03648a2a91f9f1091cd21bd4cd6ca092ddb25640
tree0f7f969f440abdce580317be0ba70aaf5216bcdc
parent953d27261e455066b17a106d9e07bab3bf12983b
bpo-43392: Optimize repeated calls to `__import__()` (GH-24735)

Implements a two steps check in `importlib._bootstrap._find_and_load()` to avoid locking when the module has been already imported and it's ready.

---

Using `importlib.__import__()`, after this, does show a big difference:

Before:
```
$ ./python -c 'import timeit; print(timeit.timeit("__import__(\"timeit\")", setup="from importlib import __import__"))'
15.92248619502061
```

After:
```
$ ./python -c 'import timeit; print(timeit.timeit("__import__(\"timeit\")", setup="from importlib import __import__"))'
1.206068897008663
```

---
Lib/importlib/_bootstrap.py
Misc/NEWS.d/next/Library/2021-03-03-13-32-37.bpo-43392.QQumou.rst [new file with mode: 0644]
Python/importlib.h