alexcrichton opened PR #4041 from less-rwlock to main:
This commit intendes to close #4025 by reducing contention on the global
rwlock Wasmtime has for module information during instantiation and
dropping a store. Currently registration of a module into this global
map happens during instantiation, but this can be a hot path as
embeddings may want to, in parallel, instantiate modules.Instead this switches to a strategy of inserting into the global module
map when aModuleis created and then removing it from the map when
theModuleis dropped. Registration in aStorenow preserves the
entireModulewithin the store as opposed to trying to only save it
piecemeal. In reality the only piece that wasn't saved within a store
was theTypeTableswhich was pretty inconsequential for core wasm
modules anyway.This means that instantiation should now clone a singluar
Arcinto a
StoreperModule(previously it cloned two) with zero managemnt on
the global rwlock as that happened atModulecreation time.
Additionally dropping aStoreagain involves zero rwlock management
and only a singleArcdrop per-instantiated module (previously it was
two).In the process of doing this I also went ahead and removed the
Module::new_with_nameAPI. This has been difficult to support
historically with various variations on the internals ofModuleInner
because it involves mutating aModuleafter it's been created. My hope
is that this API is pretty rarely used and/or isn't super important, so
it's ok to remove.Finally this change removes some internal
Arclayerings that are no
longer necessary, attempting to use eitherTor&Twhere possible
without dealing with the overhead of anArc.Closes #4025
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
alexcrichton submitted PR review.
alexcrichton created PR review comment:
I ideally wanted to remove this
Arcas well but theGlobalModuleRegistryneeded to hang on to something and theModuleisn't constructed yet (andModuleneeds the dtor to unregister), so I went ahead and left this in anArcbut at thisModulelayer instead of the previous layer.
alexcrichton updated PR #4041 from less-rwlock to main.
alexcrichton updated PR #4041 from less-rwlock to main.
alexcrichton requested fitzgen for a review on PR #4041.
fitzgen submitted PR review.
fitzgen submitted PR review.
fitzgen created PR review comment:
Why switch
modules_with_codefrom aBTreeMapto a sortedVec? This is introducingO(n)runtime to registering new modules. Is the binary search in the sortedVecreally that much faster that we are willing to take the hit onO(n)module registration?
alexcrichton submitted PR review.
alexcrichton created PR review comment:
This was a drive-by cleanup I figured I'd do while I was changing things. When thinking again about this I figured that most stores would only ever have a small handful of modules so the overhead of
BTreeMapprobably wasn't worth it. If you'd prefer though I can add the map back in
fitzgen submitted PR review.
fitzgen created PR review comment:
Does the
BTreeMapactually have overhead for a small number of modules? If they all fit in a single node, then I think there wouldn't be any overhead at all?Without profiling evidence to the contrary, I'd lean towards keeping the
BTreeMapand avoiding turning registration fromO(log n)toO(n). Especially since, with the component model, we will expect smaller but more modules to become the norm.
fitzgen submitted PR review.
fitzgen submitted PR review.
alexcrichton updated PR #4041 from less-rwlock to main.
alexcrichton merged PR #4041.
Last updated: Dec 13 2025 at 19:03 UTC