Skip to content

perf: Avoid heap allocation in cluster_dist_write node list#2857

Merged
michael-grunder merged 1 commit into
phpredis:developfrom
iliaal:perf/cluster-dist-stack
Jun 2, 2026
Merged

perf: Avoid heap allocation in cluster_dist_write node list#2857
michael-grunder merged 1 commit into
phpredis:developfrom
iliaal:perf/cluster-dist-stack

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Jun 2, 2026

cluster_dist_write emalloc'd a small int array (master + slaves) on every read issued under a failover-distribution mode, then freed it. A shard's replica count is small in practice.

Build the index list on a 16-element stack array and fall back to emalloc only for larger fan-outs. Both free sites are guarded against freeing the stack.

Compile-verified against PHP 8.4 (no cluster available for a runtime test).

cluster_dist_write emalloc'd a small int array (master + slaves) on every
read command issued under a failover-distribution mode, then freed it.
A shard's replica count is small in practice, so build the index list on
a 16-element stack array and only fall back to emalloc for larger
fan-outs. Both free sites are now guarded against freeing the stack.
@michael-grunder michael-grunder merged commit 9623a66 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