Uh oh!
There was an error while loading. Please reload this page.
gh-133968: Add fast path to PyUnicodeWriter_WriteStr() - #133969
Merged
Conversation
Don't call PyObject_Str() if the input type is str.
vstinner
commented
May 13, 2025
MemberAuthor
Microbenchmark: Mean +- std dev: [ref] 70.5 ns +- 1.1 ns -> [change] 58.3 ns +- 3.8 ns: 1.21x faster from_testcapiimportPyUnicodeWriterimportpyperfrange_100=range(100)
defbench_write_str():
writer=PyUnicodeWriter(0)
for_inrange_100:
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
writer.write_str("true")
runner=pyperf.Runner()
runner.bench_func('write_str', bench_write_str, inner_loops=1_000) |
vstinner
commented
May 13, 2025
MemberAuthor
JSON benchmark: #133832 (comment)
Encoding booleans is now up to 1.61x faster which is quite appealing! |
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
miss-islington pushed a commit
to miss-islington/cpython
that referenced
this pull request
May 13, 2025
GH-133971 is a backport of this pull request to the 3.14 branch. |
vstinner
commented
May 13, 2025
MemberAuthor
When I wrote PyUnicodeWriter_WriteStr(), I skipped this fast path since PyObject_Str() already has a fast path. But it seems like adding one in PyUnicodeWriter_WriteStr() makes a big difference on microbenchmarks! |
vstinner added a commit
that referenced
this pull request
May 13, 2025
Pranjal095 pushed a commit
to Pranjal095/cpython
that referenced
this pull request
Jul 12, 2025
…133969) Don't call PyObject_Str() if the input type is str.
taegyunkim pushed a commit
to taegyunkim/cpython
that referenced
this pull request
Aug 4, 2025
…133969) Don't call PyObject_Str() if the input type is str.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Don't call PyObject_Str() if the input type is str.