From 640ed13fcc81fbccc632872ff00da2edfd2087ff Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 2 Jun 2026 18:13:43 -0400 Subject: [PATCH] perf: Drop redundant liveness probe in redis_sock_read_bulk_reply redis_sock_read_bulk_reply called redis_check_eof(), which issues a php_stream_eof() probe (a recv(MSG_PEEK) syscall when the stream buffer is drained), before reading the bulk body. Every caller reaches this function only after successfully reading the bulk-length header on the same socket, which already proved the stream live, so the probe is redundant and adds a kernel round-trip to the dominant GET/HGET/MGET read path. Replace it with a cheap NULL-stream guard. A disconnect that happens mid-read is still caught by the existing php_stream_eof() check inside the read loop. --- library.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library.c b/library.c index 65d7c768..2c036be3 100644 --- a/library.c +++ b/library.c @@ -784,7 +784,12 @@ redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes) return NULL; } - if (-1 == bytes || -1 == redis_check_eof(redis_sock, 1, 0)) { + /* The caller reaches this only after successfully reading the bulk + * header on this socket, which already proved the stream live, so the + * php_stream_eof() liveness probe redis_check_eof() performs is + * redundant here. A mid-read disconnect is still caught by the read + * loop below. Keep a cheap NULL-stream guard for safety. */ + if (-1 == bytes || redis_sock->stream == NULL) { return NULL; }