GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Optimize posixmodule.c:fill_time for typical timestamps · Issue #138535 · python/cpython

Optimize posixmodule.c:fill_time for typical timestamps #138535

New issue
Copy link
New issue
Copy link
Closed
Closed
Optimize posixmodule.c:fill_time for typical timestamps#138535
Copy link
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

Description

@jbosboom
jbosboom
opened on Sep 5, 2025
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

  • gh-138535: Optimize fill_time for typical timestamps #138537
  • gh-138535: Pass directly state to posix fill_time() #138693

Activity

  1. jbosboom
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Sep 5, 2025
  2. StanFromIreland
    added
    performancePerformance or resource usagePerformance or resource usage
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Sep 5, 2025
  3. vstinner
    added a commit that references this issue on Sep 9, 2025

    gh-138535: Optimize fill_time for typical timestamps (#138537)

    d4825ac
  4. vstinner
    closed this as completedon Sep 9, 2025
  5. vstinner
    added 2 commits that reference this issue on Sep 9, 2025

    pythongh-138535: Pass directly state to posix fill_time()

    959e267

    gh-138535: Pass directly state to posix fill_time() (#138693)

    6b7b9d0
  6. lkollar
    added 2 commits that reference this issue on Sep 9, 2025

    pythongh-138535: Optimize fill_time for typical timestamps (python#13…

    9204500

    pythongh-138535: Pass directly state to posix fill_time() (python#138693

    8db209b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.