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 — `os.DirEntry.is_junction` can be ~twice as fast · Issue #108717 · python/cpython

os.DirEntry.is_junction can be ~twice as fast #108717

New issue
Copy link
New issue
Copy link
Closed
#108718
Closed
os.DirEntry.is_junction can be ~twice as fast#108717
#108718
Copy link
Assignees
sobolevn
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usage

Description

@sobolevn
sobolevn
opened on Aug 31, 2023
Issue body actions

Right now it is implemented as:

cpython/Modules/posixmodule.c

Lines 14566 to 14583 in 79823c1

/*[clinic input]
os.DirEntry.is_junction -> bool
defining_class: defining_class
/
Return True if the entry is a junction; cached per entry.
[clinic start generated code]*/
static int
os_DirEntry_is_junction_impl(DirEntry *self, PyTypeObject *defining_class)
/*[clinic end generated code: output=7061a07b0ef2cd1f input=475cd36fb7d4723f]*/
{
#ifdef MS_WINDOWS
return self->win32_lstat.st_reparse_tag == IO_REPARSE_TAG_MOUNT_POINT;
#else
return 0;
#endif
}

Removing unused defining_class: defining_class from clinic has one big adavantage (aside from the fact that it is unused in the first place): it speeds up is_junction call.

The exact benchmark is system-dependent, here are my numbers (note, that I am on macos and always get False as the result).

Setup:

  • ./configure --with-pydebug && make -j
  • Install pyperf
  • pyperf timeit --setup 'import os; d = os.scandir("."); d1 = next(d); d.close()' 'd1.is_junction()'

With defining_class:

(.venv) ~/Desktop/cpython  main ✔                                                      1 ⚠️
» pyperf timeit --setup 'import os; d = os.scandir("."); d1 = next(d); d.close()' 'd1.is_junction()' 
.....................
Mean +- std dev: 46.1 ns +- 0.5 ns

Without:

(.venv) ~/Desktop/cpython  main ✗                                                         
» pyperf timeit --setup 'import os; d = os.scandir("."); d1 = next(d); d.close()' 'd1.is_junction()'
.....................
Mean +- std dev: 25.0 ns +- 0.3 ns

This happens because is_junction def is changed from METH_METHOD|METH_FASTCALL|METH_KEYWORDS to METH_NOARGS.

I have a PR ready.

Linked PRs

  • gh-108717: Speedup os.DirEntry.is_junction function #108718

Activity

  1. sobolevn
    added
    performancePerformance or resource usagePerformance or resource usage
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Aug 31, 2023
  2. sobolevn
    self-assigned this
    on Aug 31, 2023
  3. sobolevn
    added a commit that references this issue on Aug 31, 2023

    pythongh-108717: Speedup `os.DirEntry.is_junction` function

    d70b2b0
  4. erlend-aasland
    linked a pull request that will close this issuegh-108717: Speedup `os.DirEntry.is_junction` function #108718on Aug 31, 2023
  5. kumaraditya303
    closed this as completedin #108718on Sep 6, 2023
  6. kumaraditya303
    added a commit that references this issue on Sep 6, 2023

    gh-108717: Speedup `os.DirEntry.is_junction` function (#108718)

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

Metadata

Metadata

Assignees

  • @sobolevn
    sobolevn

Labels

extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usage

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.