perf(runtime): migrate std::sync::Mutex to parking_lot where not held across await#430
Open
lgahdl wants to merge 1 commit into
Open
perf(runtime): migrate std::sync::Mutex to parking_lot where not held across await#430lgahdl wants to merge 1 commit into
lgahdl wants to merge 1 commit into
Conversation
… across await
Audited every std::sync::Mutex site named in the issue: all are short
critical sections over plain data with no guard held across an
.await - confirmed per site, not assumed (host/logs/store.rs is real
production code; the rest are test-only or test_utils mocks). Moved
each to parking_lot::Mutex, dropping the poison handling on lock()
(.unwrap(), .expect("... poisoned"), .unwrap_or_else(|e| e.into_inner()))
since parking_lot never poisons.
parking_lot was already in the tree transitively (0.12.5); added as
a direct workspace dependency, .workspace = true in nexum-runtime's
[dependencies] (host/logs/store.rs is real code) and nexum-sdk's
[dev-dependencies] (tracing.rs's Mutex is test-only, so this never
touches the wasm32 guest build - confirmed by building all 12 guest
modules for wasm32-wasip2 after the change).
crates/nexum-runtime/src/host/pool_router.rs, named in the issue's
scope list alongside `ledger`/`watched` Mutex fields, no longer
exists - grepped the whole tree for both, found neither. That part
of the original scope is moot; nothing left to migrate there.
No locks held across .await anywhere in the touched files - verified
directly against each site, not inferred from context - so no
tokio::sync::Mutex conversions were needed. The one pre-existing
tokio::sync lock is untouched, as scoped.
Fixes nullislabs#280.
lgahdl
force-pushed
the
perf/280-parking-lot-migration
branch
from
July 17, 2026 14:14
bbb3915 to
1841607
Compare
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.
Summary
Fixes #280. Migrated every
std::sync::Mutexsite the issue named toparking_lot::Mutex— faster under contention, one word instead of a boxed OS primitive, no lock poisoning.Audited each site individually before migrating (the issue's own explicit caveat — a guard held across an
.awaitmust not become aparking_lotguard, since it's!Sendand would block the executor thread):crates/nexum-runtime/src/host/logs/{mod,stdio,store}.rs—store.rsis real production code (InMemoryRunLogStore);mod.rs/stdio.rssites are#[cfg(test)]mocks. All non-async or async-but-lock-dropped-before-any-.await.crates/nexum-runtime/src/test_utils/{chain,clock,store}.rs—test-utils-feature-gated mocks.chain.rs'sasync move { ... }blocks acquire the lock, do synchronous work, and return — never await while holding it. Verified directly, not inferred.crates/nexum-sdk/src/tracing.rs— the oneMutexhere is inside#[cfg(test)] mod tests, so it's a[dev-dependencies]addition and never touches the actual wasm32 guest build.Scope correction:
crates/nexum-runtime/src/host/pool_router.rs, named in the issue alongsideledger/watchedMutex fields, no longer exists — grepped the whole tree for both, found neither. That part of the issue's scope is stale; nothing to migrate there.parking_lotwas already in the tree transitively (0.12.5, percargo tree), so adding it as a direct dependency resolved to the same version —Cargo.lockdiff is just two new dependency-edge lines, no version bumps.Dropped the poison-handling boilerplate everywhere it touched (
.unwrap(),.expect("... poisoned"),.unwrap_or_else(|e| e.into_inner())) sinceparking_lot::Mutex::lock()returns the guard directly.The one existing
tokio::synclock is untouched, as scoped by the issue.Test plan
cargo build --release --target wasm32-wasip2for all 12 guest modules — clean (confirms thenexum-sdkdev-dependency never reaches the wasm32 build)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings— cleancargo fmt --all -- --check— cleancargo test --workspace --all-features --locked— full suite green