Skip to content

Reduce unnecessary work in FileIO #159446

Open

Description

@cmaloney

Feature or enhancement

Reduce number of instructions run and runtime. This is generally removing unnecessary work such as a TypeError always being constructed when FileIO is given a string filename. A second method is reducing GIL acquisitions in common paths. Measuring with the callgrind tool on my x64 linux desktop on an LTO build FileIO(path).readall() executes 23% fewer instructions and runs over 5% faster reading small files in full with these changes:

  • When FileIO is constructed on a filename string currently a TypeError is raised then caught because the constructor calls PyLong_AsInt then checks for an error rather than a fast inline _PyIndex_Check.
  • In FileIO.readall() do a single long GIL release rather than reacquiring the GIL for each read(). PyErr_CheckSignals is still checked at the same frequency.

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

Activity

  1. self-assigned this
    on Oct 15, 2026
  2. added 2 commits that reference this issue on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirperformancePerformance or resource usagetopic-IOtype-refactorCode refactoring (with no changes in behavior)

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions