Fix GH-23457: imagebmp() is extremely slow when writing to a file - #23460
Closed
lazerg wants to merge 1 commit into
Closed
Fix GH-23457: imagebmp() is extremely slow when writing to a file#23460lazerg wants to merge 1 commit into
lazerg wants to merge 1 commit into
Conversation
Member
|
is it a bug fix ? no, let s target master here. Thanks |
Contributor
|
@devnexen using 40 seconds for something that should go in <0.1 seconds is a bug in my book |
Member
|
ah ok I just read the bug report, ok that makes sense then. |
Member
|
Might be best to rephrase the PR description a bit, e.g. imagexbm does not look fixed to me. As far as imagebmp goes however, it s looking good. |
Contributor
Author
|
You're right, imagexbm() writes through putBuf, not putC, so it never had this bug. Reworded the description to say that instead of grouping it with the others. NEWS and the fix itself only ever named imagebmp() so those didn't need a change. |
devnexen
approved these changes
Aug 26, 2026
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.
imagebmp() writes its pixel data a byte at a time, and the gd stream context turned each of those bytes into its own php_stream_write() call. PHP streams do no write buffering, so a 1920x1080 truecolor image cost about six million write syscalls. libgd's own FILE context does not show this because stdio buffers for it.
Buffering the stream context in 8 KB chunks takes that image from 9.5s to 0.02s here, with byte-identical output. imagewbmp(), imagegd() and imagegd2() go through the same context and were writing per byte too, so they get the same fix. imagexbm() goes through the same context but writes its output via putBuf rather than per-byte putC, so it was not affected by this bug and sees no change from this patch.
Fixes #23457