Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions core/src/main/java/org/apache/accumulo/core/data/Mutation.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
*/
public class Mutation implements Writable {

// the exact upper boundary for the initial array size doesn't matter, so long as it's high enough
// to avoid resizing if the user has any reasonable number of column updates in a single mutation;
// this value, near 100_000, was chosen to try to optimize memory allocation to typical hardware
// page sizes, accounting for 16 bytes overhead for the array, that works with either 32-bit
// compressed object references or native 64-bit references, while keeping the value reasonable
private static final int MAX_INITIAL_ARRAY_SIZE = 100_348;

/**
* Internally, this class keeps most mutation data in a byte buffer. If a cell value put into a
* mutation exceeds this size, then it is stored in a separate buffer, and a reference to it is
Expand Down Expand Up @@ -1255,19 +1262,22 @@ private byte[] readBytes(UnsynchronizedBuffer.Reader in) {
public List<ColumnUpdate> getUpdates() {
serialize();

UnsynchronizedBuffer.Reader in = new UnsynchronizedBuffer.Reader(data);

if (updates == null) {
var in = new UnsynchronizedBuffer.Reader(data);

if (entries == 1) {
updates = Collections.singletonList(deserializeColumnUpdate(in));
} else {
ColumnUpdate[] tmpUpdates = new ColumnUpdate[entries];
// if the number of column updates is excessive, then the performance will be slowed due to
// resizing the ArrayList to meet the requested capacity
int initialArraySize = Math.min(entries, MAX_INITIAL_ARRAY_SIZE);
var tmpUpdates = new ArrayList<ColumnUpdate>(initialArraySize);

for (int i = 0; i < entries; i++) {
tmpUpdates[i] = deserializeColumnUpdate(in);
tmpUpdates.add(deserializeColumnUpdate(in));
}

updates = Arrays.asList(tmpUpdates);
updates = tmpUpdates;
}
}

Expand Down