Add write buffering to Windows SDL_IOStream (#12424) #14794
Merged
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.
Description
Original implementation for SDL_IOStream write file API was incredibly slow on Windows due to not having basic buffering. A write up at nmlgc/ssg#93 details critical performance issues due to this.
This PR adds basic buffering of size 1024 (same as
windows_file_readread buffer) towindows_file_writeand also implemented auto flushing for the new write buffer before read and seek operations. This adds safety by default. Users don't need to manually callSDL_FlushIO()between write to reads and write to seek transactions at the cost of (very) minimal speed overhead, which is negligible given the buffer massively improves write speed on Windows.Existing Issue(s)
Fixes #12424
Tested
Built SDL3 locally and on this branch and wrote a minimal benchmark test for the following scenarios:
With no write buffer:
With write buffer:
Small writes ~95x faster, medium writes ~4x faster, large writes slightly slower but expected, SDL_SaveBMP_IO ~6x faster.