apple / apple/foundationdb

Reduce arena allocation overhead in MutationRef deep-copy constructors

Open
#13,269 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
1.6k
Avg merge
1d 20h
Merged PRs (30d)
126

Description

## Description

`MutationRef` deep-copy construction currently performs two independent arena allocations per mutation when copying payload data, even though both payloads belong to the same mutation object and are always constructed together.

This introduces unnecessary/extra allocator overhead in hot paths involving large numbers of mutation constructions, particularly for workloads dominated by small-to-medium mutation payloads.

## Root Cause

In `fdbclient/include/fdbclient/CommitTransaction.h`, the deep-copy constructors currently copy `param1` and `param2` independently:

```cpp
MutationRef(Arena& to, Type t, StringRef a, StringRef b)
: type(t), param1(to, a), param2(to, b), corrupted(false) {}

MutationRef(Arena& to, const MutationRef& from)
: type(from.type), param1(to, from.param1), param2(to, from.param2), corrupted(false) {}
```

Each `StringRef(Arena&, ...)` construction performs its own arena allocation. As a result, every deep-copied mutation performs two separate arena allocations.

This affects hot paths such as:

* `VectorRef::emplace_back_deep`
* `VectorRef::push_back_deep`
* commit batching

## Proposed Solution

Reduce the number of arena allocations performed during `MutationRef` deep-copy construction by storing copied mutation payload data more efficiently within the arena allocation path, while preserving existing `StringRef` ownership behavior.

Contributor guide

Open the contributing guide

Research direction

Start in fdbclient/include/fdbclient/CommitTransaction.h and inspect the MutationRef constructors that copy param1 and param2, then trace VectorRef::emplace_back_deep and push_back_deep. Determine how to reduce allocations for payloads constructed together while preserving StringRef ownership behavior. Done means deep-copy construction uses fewer arena allocations without changing mutation contents or behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
databases, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.