Closed
Description
I modified the json module to replace the private _PyUnicodeWriter C API with the public PyUnicodeWriter C API:
Problem: it made the json module slower. Let's investigate what's going on.
Linked PRs
- gh-133968: Use private unicode writer for json #133832
- gh-133968: Add fast path to PyUnicodeWriter_WriteStr() #133969
- [3.14] gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969) #133971
- gh-133968: Add PyUnicodeWriter_WriteASCII() function #133973
- [3.14] gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973) #134974
- gh-133968: Update PyUnicodeWriter_WriteASCII() documentation #135297
Metadata
Metadata
Assignees
Labels
Projects
Status
Done
Activity
vstinner commentedon May 13, 2025
See also #133186.
pythongh-133968: Add fast path to PyUnicodeWriter_WriteStr()
gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (#133969)
pythongh-133968: Add fast path to PyUnicodeWriter_WriteStr() (pythonG…
[3.14] gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969
pythongh-133968: Add PyUnicodeWriter_WriteASCII() function
pythongh-133968: Add PyUnicodeWriter_WriteASCII() function
encukou commentedon May 15, 2025
Could you try overoptimizing
PyUnicodeWriter_WriteUTF8
and benchmarking that, to see how fast the existing function can “theoretically” be?I'm thinking something like:
"null"
etc) to besize_t
-aligned_PyUnicodeWriter_WriteUTF8_SmallAligned
, which requiressize_t
-aligned input and size <= sizeof(size_t
)PyUnicodeWriter_WriteUTF8
a macro that calls_PyUnicodeWriter_WriteUTF8_SmallAligned
if the need are met, andPyUnicodeWriter_WriteUTF8
otherwise19 remaining items