SIGN IN SIGN UP

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
```

---
G
Germán Méndez Bravo committed
03648a2a91f9f1091cd21bd4cd6ca092ddb25640
Parent: 953d272
Committed by GitHub <noreply@github.com> on 8/12/2021, 6:23:29 PM