You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Feature or enhancement
Proposal:
os.stateventually callsfill_timeto initialize the timestamps in theos.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 whens_index == -1(forst_birthtime). Because we can immediately store the longs we do create in thestat_result, we can avoid the null checks implied in Py_XDECREF.This improves
python -m pyperf timeit -s 'import os' 'os.stat(".")'from1.26 us +- 0.02 usto1.15 us +- 0.01 uson Linux 6.16.2.arch1-1 and a btrfs filesystem.I found this while implementing
os.stat_result.st_birthtimeon 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
Linked PRs