FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

perf: Fuse redis_cmd_append_sstr into a single reserve and write by iliaal · Pull Request #2864 · phpredis/phpredis · GitHub

perf: Fuse redis_cmd_append_sstr into a single reserve and write - #2864

Open
iliaal wants to merge 1 commit into
phpredis:developfrom
iliaal:perf/fuse-cmd-append-sstr
Open

perf: Fuse redis_cmd_append_sstr into a single reserve and write#2864
iliaal wants to merge 1 commit into
phpredis:developfrom
iliaal:perf/fuse-cmd-append-sstr

Conversation

iliaal commented Jun 3, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

redis_cmd_append_sstr frames one RESP bulk argument ($<len>\r\n<data>\r\n) and runs for every argument of every command; all the typed _int/_long/_dbl/_zval/_zstr/_key appenders funnel through it. It did five separately bounds-checked smart_string appends per argument. This formats the length prefix up front so the whole frame size is known, reserves it with one smart_string_alloc, then writes the frame directly: same bytes on the wire, one capacity check instead of five. A ZEND_ASSERT documents the existing non-negative-length precondition.

Verified on PHP 8.4 across value lengths spanning page boundaries, large and negative integer args, floats, binary payloads with NUL and CRLF, and high-arity MGET/HSET: no leaks, 33/34 project suite methods pass (the one failure, testXRange, fails identically on develop). Buffer math and reply-type equivalence were independently reviewed.

redis_cmd_append_sstr frames one RESP bulk argument and runs for every
argument of every command (the hottest packing symbol; all the typed
_int/_long/_dbl/_zval/_zstr/_key appenders funnel through it). It did
five separately bounds-checked smart_string appends per argument.

Format the length prefix up front so the whole frame size is known,
reserve it with one smart_string_alloc, then write the frame directly.
Same bytes on the wire; one capacity check instead of five.

A ZEND_ASSERT documents the existing non-negative-length precondition
(a negative length would mean a caller truncated a >INT_MAX size_t into
the int parameter; that int-length contract is pervasive in the packing
layer and unchanged here).

Verified on PHP 8.4: value lengths across page boundaries (0, 4095/96/97,
65535/36, 1MB), large/negative integer args, float scores, binary
key/value with NUL+CRLF, 500-arg MGET, 300-field HSET, no leaks under
report_memleaks, and 33/34 project suite methods (the one failure,
testXRange, fails identically on develop and is unrelated).
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL