CommandArguments causes unnecessary array copies for large commands
Author: leonchen83Created Sep 14, 2026Updated Sep 18, 2026
Jedis Version
8.0.1
Java Version
Openjdk 25
Problem
When constructing large commands (ZADD, MSET, HMSET with hundreds of members), CommandArguments causes unnecessary array copies in two ways:
1. ArrayList reallocation
public CommandArguments(ProtocolCommand command) {
args = new ArrayList<>(); // default capacity = 10
args.add(command);
}2. Raw defensive copy
public Raw(byte[] raw) {
this.raw = Arrays.copyOf(raw, raw.length);
}Raw is only used transiently: CommandArguments → Protocol.sendCommand() → RedisOutputStream → socket. After serialization it's never read again. For ZADD 500 members: 500 unnecessary arraycopy calls, ~16KB wasted.
Proposal
Fix 1: Add initial capacity constructor
public CommandArguments(ProtocolCommand command) {
this(command, 10);
}
public CommandArguments(ProtocolCommand command, int initialCapacity) {
args = new ArrayList<>(initialCapacity);
args.add(command);
keys = new ArrayList<>(DEFAULT_KEYS_CAPACITY);
cachedHashSlots = null;
}Fix 2: Remove defensive copy or add zero-copy path
public Raw(byte[] raw) {
this.raw = raw;
}Profiling Evidence
See attached async-profiler flame graph
Source: redis/jedis