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
|