New submission from Ivan Babrou :
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, "",
0x76bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.33>
05:31:56.699743 newfstatat(AT_FDCWD, "",
0x76bc4b70, 0) = -1 ENOENT (No such file or directory) <0.61>
05:31:56.701328 newfstatat(AT_FDCWD, "",
0x76bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.37>
05:31:56.702171 newfstatat(AT_FDCWD, "",
0x76bc4b70, 0) = -1 ENOENT (No such file or directory) <0.31>
05:31:56.703614 newfstatat(AT_FDCWD, "",
0x76bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.31>
05:31:56.704421 newfstatat(AT_FDCWD, "",
0x76bc4b70, 0) = -1 ENOENT (No such file or directory) <0.28>
05:31:56.705751 newfstatat(AT_FDCWD, "",
0x76bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.39>
05:31:56.706691 newfstatat(AT_FDCWD, "",
0x76bc4b70, 0) = -1 ENOENT (No such file or directory) <0.28>
05:31:56.708148 newfstatat(AT_FDCWD, "",
0x76bc4cf0, 0) = -1 ENOENT (No such file or directory) <0.32>
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
real0m23.481s
user0m22.845s
sys 0m0.649s
Speedup after not calling into inspect.stack():
$ time sudo salt-call --local test.ping
local:
True
real0m3.661s
user0m3.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 "" in inspect
type: performance
versions: Python 3.7
___
Python tracker
<https://bugs.python.org/issue39643>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com