Repository navigation
Parallelize merge of per-thread changes into global map. - #5415
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Consensus-critical concurrency and ownership changes require human review backed by test and race-detector validation.
0 open findings
What changed in this PR
Optimizes Stellar Core’s parallel Soroban apply pipeline by merging per-thread changes into separate global-map shards concurrently.
Changes:
- Parallelizes shard merges while keeping restored-entry merging sequential.
- Caches ledger-key hashes and centralizes parallel-apply types.
- Adds move-based scope adoption to reduce entry copies.
| File | Description |
|---|---|
| src/transactions/TransactionFrameBase.h | Uses the extracted parallel-apply types. |
| src/transactions/ParallelApplyUtils.h | Declares sharded state and updated merge interfaces. |
| src/transactions/ParallelApplyUtils.cpp | Implements concurrent shard merges and cached-key lookups. |
| src/transactions/ParallelApplyTypes.h | Defines cached keys and shared parallel-apply types. |
| src/ledger/LedgerManagerImpl.cpp | Updates the stage merge call. |
| src/ledger/LedgerEntryScope.h | Declares move-based adoption overloads. |
| src/ledger/LedgerEntryScope.cpp | Implements move-based adoption. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
sisuresh
reviewed
Oct 15, 2026
dmkozh
force-pushed
the
par_commit
branch
3 times, most recently
from
October 16, 2026 16:59
a0157cf to
1fa367b
Compare
sisuresh
approved these changes
Oct 17, 2026
When we commit the changes from Soroban apply threads to the global state map, we can shard the output such that every worker only writes into a single shard (thus avoiding any synchronization). Besides the parallelization, this includes a few micro-optimizations that help us avoid extra hash re-computations and copies.
graydon
approved these changes
Oct 20, 2026
graydon
left a comment
Contributor
There was a problem hiding this comment.
A little late to the party but this is cool! I never would have thought of it. Might do with a bit of an additional comment explaining the two dimensions of tasks?
graydon
reviewed
Oct 20, 2026
| // Merges the entries of every thread that belong to shard `shardIdx`. | ||
| // Used as the per-worker body of the parallelized | ||
| // commitChangesFromThreads: every entry belongs to exactly one shard, so | ||
| // concurrent calls for different shards need no synchronization. |
Contributor
There was a problem hiding this comment.
Suggested change
| // concurrent calls for different shards need no synchronization. | |
| // concurrent calls for different shards need no synchronization. | |
| // | |
| // Note: the number of shards is separate from and likely different | |
| // from the number of transaction clusters or tx-apply tasks. The | |
| // per-shard commits happen from a separate set of per-shard tasks | |
| // spawned after the tx-apply tasks are finished. |
graydon
reviewed
Oct 20, 2026
| ParallelApplyEntryMap<staticScope> mGlobalEntryMap; | ||
| // | ||
| // The map is sharded by key hash, so that it's possible to update it | ||
| // concurrently using as many threads as there are shards. |
Contributor
There was a problem hiding this comment.
Suggested change
| // concurrently using as many threads as there are shards. | |
| // concurrently using as many threads as there are shards. | |
| // | |
| // Note: the map sharding is separate from the partitioning of txs | |
| // into apply clusters. Sharding exists to enable parallel write-back | |
| // of apply clusters at the end of each stage, and the same sharding | |
| // is used from stage to stage even as the tx clustering changes. |
SirTyson
added a commit
to SirTyson/stellar-core
that referenced
this pull request
Nov 9, 2026
Brings overlay-v2-shared up to date with master. The previous master merge (b90d48e, stellar#5428) was recorded with master's tip 100cc38 missing from its parents, so this merge used 100cc38 as its base (temporary graft of b90d48e, removed afterwards). Notable master changes brought in: - Protocol 30: CURRENT_LEDGER_PROTOCOL_VERSION follows MAX_SUPPORTED_PROTOCOL_VERSION; CAP-0084 and CAP-0087 ungated, p29 and p30 Soroban hosts (stellar#5472, stellar#5478, stellar#5484, stellar#5483). - Millisecond-resolution close times at protocol 30 (stellar#5423): ConsensusTime/ApplyTime types, STELLAR_VALUE_SIGNED_MS and STELLAR_VALUE_EMPTY_TX_SET_MS. - Tx set validity hardening (stellar#5481), lower max message size in protocol 29 (stellar#733), sub-second ledger edge-case fixes. - Simplified ledger view hierarchy (stellar#5461); the overlay-only-mode sequence number skip now lives in TransactionFrame::checkValid. - Banned accounts deprecated (CAP-0077 is active). - Apply-path performance work (stellar#5402, stellar#5411, stellar#5414, stellar#5415, stellar#5418, stellar#5421, stellar#5436, stellar#5286), apply-load tx set construction mode (stellar#5448), --check-lcm (stellar#5435), v29.0.0 release merge. Conflict resolution: - Files overlay-v2-shared deleted and master modified (the C++ overlay, TransactionQueue, TransactionQueueTests, UpgradesTests, private/Horizon/RPC workflows): kept deleted. Master's changes to them are C++ overlay peer/flow-control logic, tx queue admission and tests for those. - Herder: kept the Rust-overlay submission path (recvTransaction returns TxSubmitStatus) and dropped the deprecated `force` parameter as master did. triggerNextLedger keeps the prepared/built tx set path from the Rust mempool, now with ConsensusTime close times and master's apply-time close-time offset. The early tx set preparation path (prepareTxSet, buildTxSet, setupTriggerNextLedger) takes ConsensusTime. Kept master's mNominatedTxSetOverride test hook (applied before the tx set is cached in the Rust overlay) and the herder.txset.build timer (now timing buildTxSet). Dropped the banned-accounts setup and tx queue maintenance. - AppConnector: dropped both ov2's maybeUpdateImmutableLedgerView and master's C++-overlay getOverlayThreadSnapshot. - LoadGenerator: master's CachedTestAccountPtr with ov2's TxSubmitStatus. - Tests: kept ov2's removal of tests that need the C++ overlay, standalone mode or the tx queue (standalone, manualclose, flooding, tx queue limits, far-future slot cleanup, herderExternalizesValuesWithProtocol, MAX_SAC_TPS, custom token, soroswap and noisy binary search apply-load tests). Added master's ms close time HerderTests and the non-canonical empty tx set test on ov2's Rust-overlay topologies. The tx set size test checks against overlay-v2's own tx set allowance. The sub-second getUpperBoundCloseTimeOffset test checks the offset directly, since there is no C++ tx queue admission. Tests that used CheckValidLedgerViewWrapper now use getLCLView(). - Cargo.lock: master's lockfile plus the overlay crate's packages, regenerated by cargo; semver-compatible duplicates take the newer version. - Build: Makefile.am keeps the Rust overlay rules and adds tracy import-chrome; ci-build.sh keeps ASAN off and takes master's -g1. - Needed to compile: PendingEnvelopes.cpp includes LedgerManager.h (master got it through the C++ OverlayManager.h); ov2's early-nomination and checkpoint-slot tests use ConsensusTime/ApplyTimeOffset; OverlayIPC tests take ledger views from the LedgerManager.
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
Parallelize merge of per-thread changes into global map.
When we commit the changes from Soroban apply threads to the global state map, we can shard the output such that every worker only writes into a single shard (thus avoiding any synchronization). Besides the parallelization, this includes a few micro-optimizations that help us avoid extra hash re-computations and copies.
These changes save ~10ms cumulatively on large benchmarks locally.
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)