From d39633bc63c3cdccc4f4fda29911b500ff8e1c90 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 3 Apr 2026 18:13:07 -0400 Subject: [PATCH 1/5] remove thread per invoke --- src/rust/src/soroban_invoke.rs | 38 ++-------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/rust/src/soroban_invoke.rs b/src/rust/src/soroban_invoke.rs index e9c5fc8c93..468f058452 100644 --- a/src/rust/src/soroban_invoke.rs +++ b/src/rust/src/soroban_invoke.rs @@ -20,30 +20,8 @@ pub(crate) fn invoke_host_function( rent_fee_configuration: CxxRentFeeConfiguration, module_cache: &SorobanModuleCache, ) -> Result> { - use std::error::Error as StdError; - type BoxStdErr = Box; - type BoxStdErrSend = Box; - type BoxStdErrSendSync = Box; - - fn sendable_str_err(str: &str) -> BoxStdErrSend { - let tmp: BoxStdErrSendSync = Box::from(str); - tmp as BoxStdErrSend - } - let hm = get_host_module_for_protocol(config_max_protocol, ledger_info.protocol_version)?; - // Rust stacks are 2MiB by default, which is a little too small - // for comfort; to give ourselves a little more breathing room - // against unforeseen bugs we use a 100MiB stack. Unfortunately - // there's no easy way to enforce this at the C++ side when the - // initial std::async parallel-exec thread is spawned, so we - // have to spawn _another_ here. On linux this is fairly fast, - // on the order of a ten-ish microseconds. - let LARGE_STACK_SIZE: usize = 100 * 1024 * 1024; // 100 MiB - let res = std::thread::scope(|scope| { - std::thread::Builder::new() - .stack_size(LARGE_STACK_SIZE) - .spawn_scoped(scope, || { - (hm.invoke_host_function)( + let res = (hm.invoke_host_function)( enable_diagnostics, instruction_limit, hf_buf, @@ -57,19 +35,7 @@ pub(crate) fn invoke_host_function( base_prng_seed, &rent_fee_configuration, module_cache, - ) - // Map non-sendable error to sendable for crossing thread boundary. - // This is crude but the error is going to be stringified on the - // bridge-crossing anyways. - .map_err(|e| sendable_str_err(&format!("{e}"))) - }) - .map_err(|_| sendable_str_err("spawn_scoped failed"))? - .join() - .map_err(|_| sendable_str_err("join failed"))? - }); - - // Map sendable error back to non-sendable -- Rust doesn't do dyn upcasts. - let res = res.map_err(|e: BoxStdErrSend| e as BoxStdErr); + ); #[cfg(feature = "testutils")] crate::soroban_test_extra_protocol::maybe_invoke_host_function_again_and_compare_outputs( From 8c7d5ef0bb995325ee96e92aaf830134b8b48db3 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 10 Apr 2026 14:03:29 -0400 Subject: [PATCH 2/5] budget opt step 1 --- src/rust/soroban/p26 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust/soroban/p26 b/src/rust/soroban/p26 index b351f88a46..3c59267f56 160000 --- a/src/rust/soroban/p26 +++ b/src/rust/soroban/p26 @@ -1 +1 @@ -Subproject commit b351f88a468d3b9e1d6de53d5b0ca585f6b7dadb +Subproject commit 3c59267f5652fd0cd182c058e9a5f6cfcf1a2330 From 5a4e17b2e99daa8d986921bbd8af45898605cdef Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 10 Apr 2026 16:45:49 -0400 Subject: [PATCH 3/5] rollback env, update benchmark config --- docs/apply-load-benchmark-sac.cfg | 2 +- scripts/run_apply_load_matrix.py | 16 ++++++---------- src/rust/soroban/p26 | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/docs/apply-load-benchmark-sac.cfg b/docs/apply-load-benchmark-sac.cfg index 7473130a40..4eaf6321f5 100644 --- a/docs/apply-load-benchmark-sac.cfg +++ b/docs/apply-load-benchmark-sac.cfg @@ -32,7 +32,7 @@ APPLY_LOAD_LEDGER_MAX_DEPENDENT_TX_CLUSTERS = 1 # operations are batched for 'classic' transactions. # This is useful to reduce the impact of non-env parts of the apply path, e.g. # when evaluating the impact of changes to env itself. -APPLY_LOAD_BATCH_SAC_COUNT = 100 +APPLY_LOAD_BATCH_SAC_COUNT = 1 # Number of ledgers to close for every iteration of search. APPLY_LOAD_NUM_LEDGERS = 100 diff --git a/scripts/run_apply_load_matrix.py b/scripts/run_apply_load_matrix.py index 2f7bf908d6..5b09aa9c52 100644 --- a/scripts/run_apply_load_matrix.py +++ b/scripts/run_apply_load_matrix.py @@ -71,44 +71,40 @@ def summary(self) -> str: SCENARIOS: tuple[Scenario, ...] = ( Scenario( model_tx="sac", - tx_count=6400, + tx_count=3200, thread_count=1, ), Scenario( model_tx="sac", - tx_count=6400, + tx_count=3200, thread_count=8, ), Scenario( model_tx="custom_token", - tx_count=3000, + tx_count=1600, thread_count=1, ), Scenario( model_tx="custom_token", - tx_count=3000, + tx_count=1600, thread_count=8, ), Scenario( model_tx="soroswap", - tx_count=1600, + tx_count=1000, thread_count=1, ), Scenario( model_tx="soroswap", - tx_count=1600, + tx_count=1000, thread_count=8, ), ) def validate_scenarios(scenarios: tuple[Scenario, ...]) -> None: - seen_identifiers: set[str] = set() for scenario in scenarios: identifier = scenario.identifier() - if identifier in seen_identifiers: - raise ValueError(f"Duplicate scenario identifier: {identifier}") - seen_identifiers.add(identifier) if scenario.model_tx != "sac": continue diff --git a/src/rust/soroban/p26 b/src/rust/soroban/p26 index 3c59267f56..b351f88a46 160000 --- a/src/rust/soroban/p26 +++ b/src/rust/soroban/p26 @@ -1 +1 @@ -Subproject commit 3c59267f5652fd0cd182c058e9a5f6cfcf1a2330 +Subproject commit b351f88a468d3b9e1d6de53d5b0ca585f6b7dadb From 0ad388f96647fa80b948e6d6f3169a5d38164f36 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Fri, 10 Apr 2026 20:41:08 +0000 Subject: [PATCH 4/5] disable test meta --- docs/apply-load-benchmark-sac.cfg | 2 ++ docs/apply-load-benchmark-token.cfg | 2 ++ src/ledger/LedgerManagerImpl.cpp | 24 +++++++++++++++++------- src/main/Config.cpp | 5 +++++ src/main/Config.h | 5 +++++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/docs/apply-load-benchmark-sac.cfg b/docs/apply-load-benchmark-sac.cfg index 4eaf6321f5..a3e7a1f240 100644 --- a/docs/apply-load-benchmark-sac.cfg +++ b/docs/apply-load-benchmark-sac.cfg @@ -16,6 +16,8 @@ APPLY_LOAD_TIME_WRITES = true # eventually, it is useful to disable these when optimizing anything besides # the metrics. DISABLE_SOROBAN_METRICS_FOR_TESTING = true +# Disable transaction metadata collection (BUILD_TESTS forces it otherwise) +DISABLE_TX_META_FOR_TESTING = true # Disable metadata output METADATA_OUTPUT_STREAM = "" # Disable metadata debug diff --git a/docs/apply-load-benchmark-token.cfg b/docs/apply-load-benchmark-token.cfg index 14dc7b3091..0c6560e812 100644 --- a/docs/apply-load-benchmark-token.cfg +++ b/docs/apply-load-benchmark-token.cfg @@ -16,6 +16,8 @@ APPLY_LOAD_TIME_WRITES = true # eventually, it is useful to disable these when optimizing anything besides # the metrics. DISABLE_SOROBAN_METRICS_FOR_TESTING = true +# Disable transaction metadata collection (BUILD_TESTS forces it otherwise) +DISABLE_TX_META_FOR_TESTING = true # Disable metadata output METADATA_OUTPUT_STREAM = "" # Disable metadata debug diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index 4c14006952..bb066f66a5 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -1596,8 +1596,9 @@ LedgerManagerImpl::applyLedger(LedgerCloseData const& ledgerData, } #ifdef BUILD_TESTS - // We always store the ledgerCloseMeta in tests so we can inspect it. - if (!ledgerCloseMeta) + // We always store the ledgerCloseMeta in tests so we can inspect it, + // unless explicitly disabled for benchmarking. + if (!ledgerCloseMeta && !mApp.getConfig().DISABLE_TX_META_FOR_TESTING) { ledgerCloseMeta = std::make_unique( header.current().ledgerVersion); @@ -2589,7 +2590,10 @@ LedgerManagerImpl::processResultAndMeta( { auto metaXDR = txMetaBuilder.finalize(result.isSuccess()); #ifdef BUILD_TESTS - mLastLedgerTxMeta.emplace_back(metaXDR); + if (!mApp.getConfig().DISABLE_TX_META_FOR_TESTING) + { + mLastLedgerTxMeta.emplace_back(metaXDR); + } #endif ledgerCloseMeta->setTxProcessingMetaAndResultPair( @@ -2598,8 +2602,11 @@ LedgerManagerImpl::processResultAndMeta( else { #ifdef BUILD_TESTS - mLastLedgerTxMeta.emplace_back( - txMetaBuilder.finalize(result.isSuccess())); + if (!mApp.getConfig().DISABLE_TX_META_FOR_TESTING) + { + mLastLedgerTxMeta.emplace_back( + txMetaBuilder.finalize(result.isSuccess())); + } #endif } } @@ -2645,8 +2652,11 @@ LedgerManagerImpl::applyTransactions( bool enableTxMeta = ledgerCloseMeta != nullptr; #ifdef BUILD_TESTS // In tests we want to always enable tx meta because we store it in - // mLastLedgerTxMeta. - enableTxMeta = true; + // mLastLedgerTxMeta, unless explicitly disabled for benchmarking. + if (!mApp.getConfig().DISABLE_TX_META_FOR_TESTING) + { + enableTxMeta = true; + } #endif std::optional sorobanConfig; if (protocolVersionStartsFrom(ltx.loadHeader().current().ledgerVersion, diff --git a/src/main/Config.cpp b/src/main/Config.cpp index 13abb8a517..9f27c03f70 100644 --- a/src/main/Config.cpp +++ b/src/main/Config.cpp @@ -172,6 +172,7 @@ Config::Config() : NODE_SEED(SecretKey::random()) BACKGROUND_OVERLAY_PROCESSING = true; PARALLEL_LEDGER_APPLY = true; DISABLE_SOROBAN_METRICS_FOR_TESTING = false; + DISABLE_TX_META_FOR_TESTING = false; BACKGROUND_TX_SIG_VERIFICATION = true; BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 14; // 2^14 == 16 kb BUCKETLIST_DB_INDEX_CUTOFF = 20; // 20 mb @@ -1180,6 +1181,10 @@ Config::processConfig(std::shared_ptr t) [&]() { DISABLE_SOROBAN_METRICS_FOR_TESTING = readBool(item); }}, + {"DISABLE_TX_META_FOR_TESTING", + [&]() { + DISABLE_TX_META_FOR_TESTING = readBool(item); + }}, {"EXPERIMENTAL_BACKGROUND_TX_SIG_VERIFICATION", [&]() { CLOG_WARNING(Overlay, diff --git a/src/main/Config.h b/src/main/Config.h index cb217d87c1..27bb04569c 100644 --- a/src/main/Config.h +++ b/src/main/Config.h @@ -550,6 +550,11 @@ class Config : public std::enable_shared_from_this // Disable expensive Soroban metrics for performance testing bool DISABLE_SOROBAN_METRICS_FOR_TESTING; + // Disable transaction metadata collection in test builds for benchmarking. + // When true, BUILD_TESTS overrides that force ledgerCloseMeta allocation + // and enableTxMeta are suppressed, avoiding significant XDR copy overhead. + bool DISABLE_TX_META_FOR_TESTING; + // Batch transactions for flooding purposes (experimental). // Has no effect on non-test builds. size_t EXPERIMENTAL_TX_BATCH_MAX_SIZE; From ad3ee5502ad82e80e48e0e7c3daaffcc3129aaf7 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 10 Apr 2026 17:15:16 -0400 Subject: [PATCH 5/5] Actually disable meta in tests (very minor) --- .../disable_meta-20260410-205536/results.csv | 7 +++ bench/disable_meta-20260410-205536/stamp | 61 +++++++++++++++++++ .../results.csv | 7 +++ .../p26_baseline_again-20260410-193305/stamp | 61 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 bench/disable_meta-20260410-205536/results.csv create mode 100644 bench/disable_meta-20260410-205536/stamp create mode 100644 bench/p26_baseline_again-20260410-193305/results.csv create mode 100644 bench/p26_baseline_again-20260410-193305/stamp diff --git a/bench/disable_meta-20260410-205536/results.csv b/bench/disable_meta-20260410-205536/results.csv new file mode 100644 index 0000000000..ffbb9cd18c --- /dev/null +++ b/bench/disable_meta-20260410-205536/results.csv @@ -0,0 +1,7 @@ +scenario,median_time_ms,p95_time_ms,p99_time_ms +"sac,TX=3200,T=1",337.0062885000008,388.6413382500008,449.63406636999326 +"sac,TX=3200,T=8",234.05063849999988,256.48933750000083,264.29044799000235 +"custom_token,TX=1600,T=1",310.4716815000029,334.2666388999983,343.7057104299992 +"custom_token,TX=1600,T=8",159.46541449999904,179.4608217500015,195.17456334999972 +"soroswap,TX=1000,T=1",444.1408194999967,479.7950516499987,504.93647869998614 +"soroswap,TX=1000,T=8",170.7175889999994,191.4872912999981,200.91390174999842 diff --git a/bench/disable_meta-20260410-205536/stamp b/bench/disable_meta-20260410-205536/stamp new file mode 100644 index 0000000000..346f682365 --- /dev/null +++ b/bench/disable_meta-20260410-205536/stamp @@ -0,0 +1,61 @@ +Warning: running non-release version v26.0.0-62-g0ad388f96 of stellar-core +v26.0.0-62-g0ad388f96 +ledger protocol version: 26 +rust version: rustc 1.88.0 (6b00bc388 2025-06-23) +soroban-env-host versions: + host[0]: + package version: 21.2.2 + git version: 7eeddd897cfb0f700f938b0c8d6f0541150d1fcb + ledger protocol version: 21 + pre-release version: 0 + rs-stellar-xdr: + package version: 21.2.0 + git version: 9bea881f2057e412fdbb98875841626bf77b4b88 + base XDR git version: 70180d5e8d9caee9e8645ed8a38c36a8cf403cd9 + host[1]: + package version: 22.0.0 + git version: 1cd8b8dca9aeeca9ce45b129cd923992b32dc258 + ledger protocol version: 22 + pre-release version: 0 + rs-stellar-xdr: + package version: 22.0.0 + git version: 715003372ea6380044b5a4a02907ff73e56ae9e7 + base XDR git version: 529d5176f24c73eeccfa5eba481d4e89c19b1181 + host[2]: + package version: 23.0.0 + git version: 688bc34e6cd15c71742139e625268c7f30f55a92 + ledger protocol version: 23 + pre-release version: 0 + rs-stellar-xdr: + package version: 23.0.0 + git version: e83a6337204ecfdb0ac0d44ffb857130c1249b1b + base XDR git version: 4b7a2ef7931ab2ca2499be68d849f38190b443ca + host[3]: + package version: 24.0.0 + git version: a37eeda815e626f416eff13f2eacb32a8b0c3729 + ledger protocol version: 24 + pre-release version: 0 + rs-stellar-xdr: + package version: 24.0.0 + git version: 07b765d3ab146f7f7ea951af1f9e41e0ece8fb48 + base XDR git version: 4b7a2ef7931ab2ca2499be68d849f38190b443ca + host[4]: + package version: 25.0.0 + git version: 6323c1fc03ecb9f53b7c1e42fd62c1bbd3aebc2c + ledger protocol version: 25 + pre-release version: 0 + rs-stellar-xdr: + package version: 25.0.0 + git version: dc9f40fcb83c3054341f70b65a2222073369b37b + base XDR git version: 0a621ec7811db000a60efae5b35f78dee3aa2533 + host[5]: + package version: 26.0.0 + git version: b351f88a468d3b9e1d6de53d5b0ca585f6b7dadb + ledger protocol version: 26 + pre-release version: 0 + rs-stellar-xdr: + package version: 26.0.0 + git version: dd7a165a193126fd37a751d867bee1cb8f3b55a6 + base XDR git version: cff714a5ebaaaf2dac343b3546c2df73f0b7a36e + +Benchmark ledgers=200 \ No newline at end of file diff --git a/bench/p26_baseline_again-20260410-193305/results.csv b/bench/p26_baseline_again-20260410-193305/results.csv new file mode 100644 index 0000000000..4fb3c5e038 --- /dev/null +++ b/bench/p26_baseline_again-20260410-193305/results.csv @@ -0,0 +1,7 @@ +scenario,median_time_ms,p95_time_ms,p99_time_ms +"sac,TX=3200,T=1",348.6932005000017,395.12184564999995,409.27602225000237 +"sac,TX=3200,T=8",242.59525600000052,266.3564931000006,277.14852171 +"custom_token,TX=1600,T=1",310.3890900000006,343.3200991000005,352.79791974000204 +"custom_token,TX=1600,T=8",163.62422350000043,180.21471705000042,187.8724304600013 +"soroswap,TX=1000,T=1",469.7830955000027,495.3508111500008,504.3309423599958 +"soroswap,TX=1000,T=8",183.22680400000036,199.4422209999998,211.36548991000078 diff --git a/bench/p26_baseline_again-20260410-193305/stamp b/bench/p26_baseline_again-20260410-193305/stamp new file mode 100644 index 0000000000..870f24320d --- /dev/null +++ b/bench/p26_baseline_again-20260410-193305/stamp @@ -0,0 +1,61 @@ +Warning: running non-release version v26.0.0-60-g8c7d5ef0b-dirty of stellar-core +v26.0.0-60-g8c7d5ef0b-dirty +ledger protocol version: 26 +rust version: rustc 1.88.0 (6b00bc388 2025-06-23) +soroban-env-host versions: + host[0]: + package version: 21.2.2 + git version: 7eeddd897cfb0f700f938b0c8d6f0541150d1fcb + ledger protocol version: 21 + pre-release version: 0 + rs-stellar-xdr: + package version: 21.2.0 + git version: 9bea881f2057e412fdbb98875841626bf77b4b88 + base XDR git version: 70180d5e8d9caee9e8645ed8a38c36a8cf403cd9 + host[1]: + package version: 22.0.0 + git version: 1cd8b8dca9aeeca9ce45b129cd923992b32dc258 + ledger protocol version: 22 + pre-release version: 0 + rs-stellar-xdr: + package version: 22.0.0 + git version: 715003372ea6380044b5a4a02907ff73e56ae9e7 + base XDR git version: 529d5176f24c73eeccfa5eba481d4e89c19b1181 + host[2]: + package version: 23.0.0 + git version: 688bc34e6cd15c71742139e625268c7f30f55a92 + ledger protocol version: 23 + pre-release version: 0 + rs-stellar-xdr: + package version: 23.0.0 + git version: e83a6337204ecfdb0ac0d44ffb857130c1249b1b + base XDR git version: 4b7a2ef7931ab2ca2499be68d849f38190b443ca + host[3]: + package version: 24.0.0 + git version: a37eeda815e626f416eff13f2eacb32a8b0c3729 + ledger protocol version: 24 + pre-release version: 0 + rs-stellar-xdr: + package version: 24.0.0 + git version: 07b765d3ab146f7f7ea951af1f9e41e0ece8fb48 + base XDR git version: 4b7a2ef7931ab2ca2499be68d849f38190b443ca + host[4]: + package version: 25.0.0 + git version: 6323c1fc03ecb9f53b7c1e42fd62c1bbd3aebc2c + ledger protocol version: 25 + pre-release version: 0 + rs-stellar-xdr: + package version: 25.0.0 + git version: dc9f40fcb83c3054341f70b65a2222073369b37b + base XDR git version: 0a621ec7811db000a60efae5b35f78dee3aa2533 + host[5]: + package version: 26.0.0 + git version: b351f88a468d3b9e1d6de53d5b0ca585f6b7dadb + ledger protocol version: 26 + pre-release version: 0 + rs-stellar-xdr: + package version: 26.0.0 + git version: dd7a165a193126fd37a751d867bee1cb8f3b55a6 + base XDR git version: cff714a5ebaaaf2dac343b3546c2df73f0b7a36e + +Benchmark ledgers=200 \ No newline at end of file