Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Optimize posixmodule.c:fill_time for typical timestamps #138535

Copy link
Copy link
@jbosboom

Description

@jbosboom
Issue body actions

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

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.