[GIT-PULLS] [php-src] PR #23460: Fix GH-23457: imagebmp() is extremely slow when writing to a file

[email protected] (lazerg)
Newsgroups php.git-pulls
Message-ID <yCIPBGDFu1jMNcQ51rCqnrSSrBLQAPDfmnM9UWt5uzQ@main.internal.php.net>
Pull Request: https://github.com/php/php-src/pull/23460
Author: lazerg

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(), imagegd2() and imagexbm() go through the same context and were writing per byte too.

Fixes #23457
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.