gh-117151: optimize BufferedWriter(), do not buffer writes that are the buffer size #118037
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.
gh-117151: optimize BufferedWriter(), do not buffer writes that are the buffer size
Hello,
I am having a look at the buffering code as part of the linked discussion, #gh-117151
One thing that was puzzling me is finding the buffering code slightly slower than the non-buffering code, given the same conditions, so I started having a deeper look into it.
Could I get a second pair of eyes on this old piece of code?
BufferedWriter()
is buffering calls that are the exact same size as the buffer.It's a very common case to read/write in blocks of the exact buffer size.
I think this might actually be the primary use case, reading in chunks from disk/network and writing to disk.
I think it shouldn't buffer in that case. It's costing an extra memory copy and the buffer will be full and have to be written in the next call anyway.
Thoughts?