Make Soroban metric batching code lock-free. - #5436
Open
dmkozh wants to merge 1 commit into
Open
Conversation
dmkozh
force-pushed
the
apply_metrics_no_sync
branch
from
August 28, 2026 21:09
716025f to
0ce3397
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors Soroban metrics collection to use thread-local accumulators and publish merged results after ledger close.
Changes:
- Introduces
SorobanApplyMetricsandSorobanMetricsRegistry. - Plumbs accumulators through transaction and operation apply paths.
- Merges worker metrics before Medida publication.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/transactions/TransactionFrameBase.h |
Extends apply interfaces with metrics. |
src/transactions/TransactionFrame.h |
Updates transaction method declarations. |
src/transactions/TransactionFrame.cpp |
Records metrics in supplied accumulators. |
src/transactions/test/TransactionTestFrame.h |
Updates test wrapper interfaces. |
src/transactions/test/TransactionTestFrame.cpp |
Supplies test-local accumulators. |
src/transactions/RestoreFootprintOpFrame.h |
Updates restore-operation interfaces. |
src/transactions/RestoreFootprintOpFrame.cpp |
Redirects restore metrics. |
src/transactions/ParallelApplyUtils.h |
Extends parallel-state interfaces. |
src/transactions/ParallelApplyUtils.cpp |
Passes metrics during pre-apply. |
src/transactions/OperationFrame.h |
Extends operation apply interfaces. |
src/transactions/OperationFrame.cpp |
Forwards operation metrics. |
src/transactions/InvokeHostFunctionOpFrame.h |
Updates host-function interfaces. |
src/transactions/InvokeHostFunctionOpFrame.cpp |
Accumulates host-function metrics locally. |
src/transactions/FeeBumpTransactionFrame.h |
Updates fee-bump interfaces. |
src/transactions/FeeBumpTransactionFrame.cpp |
Forwards metrics to inner transactions. |
src/transactions/ExtendFootprintTTLOpFrame.h |
Updates TTL-extension interfaces. |
src/transactions/ExtendFootprintTTLOpFrame.cpp |
Redirects TTL metrics. |
src/test/fuzz/targets/TxFuzzTarget.cpp |
Supplies fuzz-local metrics. |
src/main/AppConnector.h |
Exposes renamed metrics registry. |
src/main/AppConnector.cpp |
Returns renamed registry type. |
src/ledger/SorobanMetrics.h |
Defines accumulators and registry. |
src/ledger/SorobanMetrics.cpp |
Implements merging and publication. |
src/ledger/LedgerManagerImpl.h |
Extends ledger-apply metrics plumbing. |
src/ledger/LedgerManagerImpl.cpp |
Collects, merges, and publishes metrics. |
src/ledger/LedgerManager.h |
Updates ledger manager interfaces. |
src/ledger/InMemorySorobanState.h |
Uses renamed registry type. |
src/ledger/InMemorySorobanState.cpp |
Updates registry parameters. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dmkozh
force-pushed
the
apply_metrics_no_sync
branch
from
August 28, 2026 21:13
0ce3397 to
68520aa
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
src/transactions/TransactionFrame.cpp:2167
- This timer no longer honors
DISABLE_SOROBAN_METRICS_FOR_TESTING: the clock reads and vector append still run and the samples are published, even though this switch exists specifically to remove metric overhead from apply-load benchmarks. The previousBatchedTimerScopewas also RAII, whereas the append at line 2198 is skipped when the exception handler below converts an apply exception intotxINTERNAL_ERROR. Please make the local timer conditional and scope-based so disabled runs do no timing/allocation and exceptional applies retain their timer sample.
auto applyStart = std::chrono::steady_clock::now();
src/ledger/LedgerManagerImpl.cpp:2632
- This transaction timer now runs unconditionally, so
DISABLE_SOROBAN_METRICS_FOR_TESTINGstill pays for two clock reads, vector growth, and later Medida publication per parallel transaction. That regresses the benchmark switch’s documented purpose and differs from the sequential apply timer, which still checks the flag. Guard both timing and sample insertion withconfig.DISABLE_SOROBAN_METRICS_FOR_TESTING.
auto applyStart = std::chrono::steady_clock::now();
Comment on lines
+2678
to
+2682
| // Stages may contain a different number of clusters, so we ensure that | ||
| // there is a corresponding metrics entry for each cluster. | ||
| if (sorobanApplyMetricsPerThread.size() < stage.numClusters()) | ||
| { | ||
| sorobanApplyMetricsPerThread.resize(stage.numClusters()); |
The previous attempt at batching Soroban metrics still had some locks and was overall more convoluted than it needs to be. With this change we simply give every thread its own metrics batch to write to, and then cleanly move the batches to the publish step for the merge and Medida export. This is slightly more plumbing, but as a result we get much more straightforward code.
dmkozh
force-pushed
the
apply_metrics_no_sync
branch
from
August 28, 2026 22:30
68520aa to
144c332
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/ledger/LedgerManagerImpl.cpp:2682
- This is a performance-focused change to the parallel apply hot path, but the PR provides no benchmark evidence that it improves throughput/latency without regression.
CONTRIBUTING.md:56-60requires such evidence for performance-impacting changes; please include representative before/after results, especially since the new per-cluster vector storage and merge may trade lock contention for allocation/cache costs.
// Stages may contain a different number of clusters, so we ensure that
// there is a corresponding metrics entry for each cluster.
if (sorobanApplyMetricsPerThread.size() < stage.numClusters())
{
sorobanApplyMetricsPerThread.resize(stage.numClusters());
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The previous attempt at batching Soroban metrics still had some locks and was overall more convoluted than it needs to be. With this change we simply give every thread its own metrics batch to write to, and then cleanly move the batches to the publish step for the merge and Medida export. This is slightly more plumbing, but as a result we get much more straightforward code.
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)