Skip to content

Conversation

@dlambrig
Copy link
Contributor

@dlambrig dlambrig commented Nov 21, 2025

Pre-reserve capacity for the tempTagMessages vector in commitMessages() to eliminate dynamic reallocations during message parsing. The tempTagMessages vector grows dynamically as messages are parsed, causing multiple reallocations in the hot commit path. Each reallocation involves allocating new memory, copying existing elements, and freeing old memory. This happens on every TLog commit, adding unnecessary overhead.

The PR estimates the number of messages based on total byte size and pre-reserve vector capacity:

size_t estimatedMsgCount = std::max(size_t(messages.size() / 150), size_t(10));
estimatedMsgCount = std::min(estimatedMsgCount, size_t(5000));
self->tempTagMessages.reserve(estimatedMsgCount);
  • 150 bytes average message size
  • Minimum reserve of 10 messages
  • Cap at 5000 messages to prevent over-allocation

A microbenchmark was written. Each tests simulate the commitMessages() parsing loop by creating realistic TagsAndMessage objects with variable sizes and pushing them into a vector. The benchmark measures three strategies: NoReserve (current implementation with dynamic growth), WithReserve (optimization using size estimation), and ExactReserve (theoretical "best case" with perfect knowledge of message count). Test scenarios cover typical TLog workloads from light (10 messages) to burst (5000 messages) loads.

Benchmark Time (ns) CPU (ns) items_per_second % Improvement
NoReserve/10/100 3571 3553 2.81M/s baseline
WithReserve/10/100 2351 2327 4.30M/s +52.7% faster
ExactReserve/10/100 2430 2397 4.17M/s +48.2% faster
NoReserve/100/150 13466 13376 7.48M/s baseline
WithReserve/100/150 10334 10228 9.78M/s +30.8% faster
ExactReserve/100/150 9292 9162 10.9M/s +46.0% faster
NoReserve/1000/200 148803 148503 6.73M/s baseline
WithReserve/1000/200 72418 72109 13.9M/s +106.0% faster
ExactReserve/1000/200 72804 72457 13.8M/s +105.0% faster
NoReserve/5000/150 797027 796247 6.28M/s baseline
WithReserve/5000/150 566643 566094 8.83M/s +40.7% faster
ExactReserve/5000/150 477830 477121 10.5M/s +66.9% faster

Tests on playstation will be posted when completed.

Code-Reviewer Section

The general pull request guidelines can be found here.

Please check each of the following things and check all boxes before accepting a PR.

  • The PR has a description, explaining both the problem and the solution.
  • The description mentions which forms of testing were done and the testing seems reasonable.
  • Every function/class/actor that was touched is reasonably well documented.

For Release-Branches

If this PR is made against a release-branch, please also check the following:

  • This change/bugfix is a cherry-pick from the next younger branch (younger release-branch or main if this is the youngest branch)
  • There is a good reason why this PR needs to go into a release branch and this reason is documented (either in the description above or in a linked GitHub issue)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-ide on Linux RHEL 9

  • Commit ID: 959d367
  • Duration 0:25:55
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-arm on Linux CentOS 7

  • Commit ID: 959d367
  • Duration 0:45:53
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: 959d367
  • Duration 1:11:14
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: 959d367
  • Duration 2:12:47
  • Result: ❌ FAILED
  • Error: Error while executing command: if python3 -m joshua.joshua list --stopped | grep ${ENSEMBLE_ID} | grep -q 'pass=10[0-9][0-9][0-9]'; then echo PASS; else echo FAIL && exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: 959d367
  • Duration 2:28:18
  • Result: ❌ FAILED
  • Error: Error while executing command: if python3 -m joshua.joshua list --stopped | grep ${ENSEMBLE_ID} | grep -q 'pass=10[0-9][0-9][0-9]'; then echo PASS; else echo FAIL && exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

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