perf: Pre-size variadic command buffers from their arguments#2865
Open
iliaal wants to merge 1 commit into
Open
perf: Pre-size variadic command buffers from their arguments#2865iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
Extends the MSET pre-sizing (phpredis#2861) to the shared multi-argument builders so a high-arity or large-payload call doesn't regrow the smart_string a 4KB page at a time through its append loop. A small shared helper, redis_zval_frame_est, returns an upper-bound RESP frame size per argument (framing overhead plus the payload length when it's already a string; non-strings get a fixed allowance). Each builder sums it over its args in a cheap read-only pre-pass and reserves once. Covers redis_key_varval_cmd (SADD/SREM/RPUSH/LPUSH/ZREM/...), gen_key_arr_cmd (their array forms), gen_vararg_cmd, redis_mget_cmd, and redis_hmset_cmd. The estimate only reads types and lengths, so it cannot change the emitted bytes; under-estimating just falls back to growth. gen_varkey_cmd (DEL/SUNION/SINTER/...) is left for a follow-up: its single-array/timeout branching makes a clean reservation point less obvious. Verified on PHP 8.4: 1000-member SADD/RPUSH/sAddArray, 50KB-blob RPUSH, 800-key MGET, 400-field HMSET incl binary fields, prefix and PHP serializer combinations; no leaks under report_memleaks; 25 project suite methods pass.
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.
Extends the MSET pre-sizing (#2861) to the shared multi-argument builders, which previously regrew the command
smart_stringone 4KB page at a time as their append loop ran. A shared helper sums an upper-bound RESP frame size over the arguments in a read-only pre-pass and reserves the buffer once. It only reads types and lengths, so it cannot change the bytes emitted, and an under-estimate falls back to normal growth.Covers
redis_key_varval_cmd(SADD/SREM/RPUSH/LPUSH/ZREM),gen_key_arr_cmd,gen_vararg_cmd,redis_mget_cmd, andredis_hmset_cmd.gen_varkey_cmd(DEL/SUNION/SINTER) is a follow-up; its single-array and timeout branching has no clean reservation point.Verified on PHP 8.4 across high-arity and large-payload calls with prefix and serializer combinations: no leaks, 25 project suite methods pass.