Skip to content

Commit a3df278

Browse files
committed
main/streams/streams: don't buffer large reads
If the read buffer is currently empty, don't buffer large reads (larger than chunk_size), because buffering would only hurt performance in such an edge case.
1 parent db480d7 commit a3df278

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

main/streams/streams.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,11 @@ PHPAPI ssize_t _php_stream_read(php_stream *stream, char *buf, size_t size)
706706
break;
707707
}
708708

709-
if (!stream->readfilters.head && ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) || stream->chunk_size == 1)) {
709+
/* if the read buffer is currently empty, don't buffer
710+
* large reads (larger than chunk_size), because
711+
* buffering would only hurt performance in such an
712+
* edge case */
713+
if (!stream->readfilters.head && ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) || stream->chunk_size == 1 || (stream->writepos == stream->readpos && size >= stream->chunk_size))) {
710714
toread = stream->ops->read(stream, buf, size);
711715
if (toread < 0) {
712716
/* Report an error if the read failed and we did not read any data

0 commit comments

Comments
 (0)