Repository navigation
Conversation
cmaloney
force-pushed
the
print_lookup_once
branch
from
October 26, 2026 17:25
395c279 to
002be51
Compare
Look up the file's write() method once per print() call, instead of once
for each argument, separator and line ending, and pass the cached ' ' and
'\n' strings for the default sep and end directly, instead of converting
them from C strings with PyFile_WriteString(). write() is called exactly
as before.
print() is up to 1.66x faster in pyperf benchmarks, 1.20x geometric
mean; for example, print('a', 1, 2.5) to a file goes from 996 ns to
687 ns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129ST3GmU89AvSnUNSXu2Yi
cmaloney
force-pushed
the
print_lookup_once
branch
from
October 26, 2026 17:26
002be51 to
abfa80d
Compare
Contributor
Author
|
(force pushed to fixup author line and make cla bot happy) |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129ST3GmU89AvSnUNSXu2Yi
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 free
to 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.
file.writeonce perprint()call, instead of once for each argument, separator and line ending.' 'and'\n'strings for the defaultsepandenddirectly, instead of converting them from C strings withPyFile_WriteString(), which runsstrlen()and the UTF-8 decoder on every call to get back the same cached string.write()receives the same calls as before. Benchmarks are in the issue: 1.20x faster geometric mean across 8 cases, 5 faster (1.12x to 1.66x) and 3 not significant.Developed with the help of AI: Claude Opus 5.5.
print()by looking upfile.writeonce per call #160725