perf: Fuse redis_cmd_append_sstr into a single reserve and write#2864
Open
iliaal wants to merge 1 commit into
Open
perf: Fuse redis_cmd_append_sstr into a single reserve and write#2864iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
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
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.
redis_cmd_append_sstrframes 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/_keyappenders funnel through it. It did five separately bounds-checkedsmart_stringappends per argument. This formats the length prefix up front so the whole frame size is known, reserves it with onesmart_string_alloc, then writes the frame directly: same bytes on the wire, one capacity check instead of five. AZEND_ASSERTdocuments 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.