Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-133968: Add fast path to PyUnicodeWriter_WriteStr()#133969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Don't call PyObject_Str() if the input type is str.
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) |
JSON benchmark:#133832 (comment)
Encoding booleans is now up to1.61x faster which is quite appealing! |
fe9f6e8
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
GH-133971 is a backport of this pull request to the3.14 branch. |
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! |
Uh oh!
There was an error while loading.Please reload this page.
Don't call PyObject_Str() if the input type is str.