New submission from Ivan Babrou <ivan@ivan.computer>:
I noticed that a program (SaltStack) is a lot slower under Python 3. After some stracing I was able to find that inspect module is to blame. In strace output I can see a ton of calls like this: 05:31:56.698829 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.000033> 05:31:56.699743 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4b70, 0) = -1 ENOENT (No such file or directory) <0.000061> 05:31:56.701328 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap_external>", 0x7ffff6bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.000037> 05:31:56.702171 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap_external>", 0x7ffff6bc4b70, 0) = -1 ENOENT (No such file or directory) <0.000031> 05:31:56.703614 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.000031> 05:31:56.704421 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4b70, 0) = -1 ENOENT (No such file or directory) <0.000028> 05:31:56.705751 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.000039> 05:31:56.706691 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4b70, 0) = -1 ENOENT (No such file or directory) <0.000028> 05:31:56.708148 newfstatat(AT_FDCWD, "<frozen importlib._bootstrap>", 0x7ffff6bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.000032> This is the entrypoint from Salt: * https://github.com/saltstack/salt/blob/9adc2214c3bb/salt/utils/decorators/__init__.py#L102 Execution with stock code: $ time sudo salt-call --local test.ping local: True real 0m23.481s user 0m22.845s sys 0m0.649s Speedup after not calling into inspect.stack(): $ time sudo salt-call --local test.ping local: True real 0m3.661s user 0m3.253s sys 0m0.423s Stackoverflow suggests that frames with virtual importlib should be skipped: * https://stackoverflow.com/questions/40945752/inspect-who-imported-me ---------- messages: 362044 nosy: Ivan Babrou priority: normal severity: normal status: open title: Python calls newfstatat for "<frozen importlib._bootstrap>" in inspect type: performance versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39643> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com