-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Description
Feature or enhancement
Proposal:
os.stat
eventually calls fill_time
to initialize the timestamps in the os.stat_result
. For typical timestamps, we can compute the nanoseconds using C arithmetic instead of creating and multiplying Python longs. Then we can skip creating the seconds long when s_index == -1
(for st_birthtime
). Because we can immediately store the longs we do create in the stat_result
, we can avoid the null checks implied in Py_XDECREF.
This improves python -m pyperf timeit -s 'import os' 'os.stat(".")'
from 1.26 us +- 0.02 us
to 1.15 us +- 0.01 us
on Linux 6.16.2.arch1-1 and a btrfs filesystem.
I found this while implementing os.stat_result.st_birthtime
on Linux and trying not to regress performance.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response