Skip to content

Using the public PyUnicodeWriter C API made the json module slower #133968

Closed

Activity

added
performancePerformance or resource usage
stdlibPython modules in the Lib dir
on May 13, 2025
vstinner

vstinner commented on May 13, 2025

@vstinner
MemberAuthor

See also #133186.

added a commit that references this issue on May 13, 2025

pythongh-133968: Add fast path to PyUnicodeWriter_WriteStr()

added a commit that references this issue on May 13, 2025

gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (#133969)

fe9f6e8
added a commit that references this issue on May 13, 2025

pythongh-133968: Add fast path to PyUnicodeWriter_WriteStr() (pythonG…

added 3 commits that reference this issue on May 13, 2025

[3.14] gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969

5632e93

pythongh-133968: Add PyUnicodeWriter_WriteASCII() function

pythongh-133968: Add PyUnicodeWriter_WriteASCII() function

encukou

encukou commented on May 15, 2025

@encukou
Member

Could you try overoptimizing PyUnicodeWriter_WriteUTF8 and benchmarking that, to see how fast the existing function can “theoretically” be?
I'm thinking something like:

  • in the JSON module, force the constants ("null" etc) to be size_t-aligned
  • add private (ABI-only) function _PyUnicodeWriter_WriteUTF8_SmallAligned, which requires size_t-aligned input and size <= sizeof(size_t)
  • make PyUnicodeWriter_WriteUTF8 a macro that calls _PyUnicodeWriter_WriteUTF8_SmallAligned if the need are met, and PyUnicodeWriter_WriteUTF8 otherwise

19 remaining items

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 dirperformancePerformance or resource usagestdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Using the public PyUnicodeWriter C API made the json module slower · Issue #133968 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant