Skip to content

perf: Avoid zero-fill in redis_key_prefix#2853

Merged
michael-grunder merged 1 commit into
phpredis:developfrom
iliaal:perf/key-prefix-no-zerofill
Jun 2, 2026
Merged

perf: Avoid zero-fill in redis_key_prefix#2853
michael-grunder merged 1 commit into
phpredis:developfrom
iliaal:perf/key-prefix-no-zerofill

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Jun 2, 2026

redis_key_prefix allocated the prefixed-key buffer with ecalloc, then overwrote the whole allocation with two memcpy calls. The zero-fill is wasted on every keyed argument when a prefix is set.

Switch to emalloc and write the single trailing NUL explicitly.

Built on PHP 8.4; testPrefix passes and a smoke test confirms the prefix is still applied on the wire.

redis_key_prefix used ecalloc to allocate the prefixed-key buffer, then
immediately overwrote the entire allocation with two memcpy calls. The
zero-fill was wasted work on every keyed argument when a prefix is set.

Use emalloc and write the single trailing NUL explicitly.
@michael-grunder michael-grunder merged commit b932035 into phpredis:develop Jun 2, 2026
42 checks passed
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.

2 participants