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 aModule
is created and then removing it from the map when
theModule
is dropped. Registration in aStore
now preserves the
entireModule
within the store as opposed to trying to only save it
piecemeal. In reality the only piece that wasn't saved within a store
was theTypeTables
which was pretty inconsequential for core wasm
modules anyway.This means that instantiation should now clone a singluar
Arc
into a
Store
perModule
(previously it cloned two) with zero managemnt on
the global rwlock as that happened atModule
creation time.
Additionally dropping aStore
again involves zero rwlock management
and only a singleArc
drop per-instantiated module (previously it was
two).In the process of doing this I also went ahead and removed the
Module::new_with_name
API. This has been difficult to support
historically with various variations on the internals ofModuleInner
because it involves mutating aModule
after 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
Arc
layerings that are no
longer necessary, attempting to use eitherT
or&T
where 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
Arc
as well but theGlobalModuleRegistry
needed to hang on to something and theModule
isn't constructed yet (andModule
needs the dtor to unregister), so I went ahead and left this in anArc
but at thisModule
layer 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_code
from aBTreeMap
to a sortedVec
? This is introducingO(n)
runtime to registering new modules. Is the binary search in the sortedVec
really 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
BTreeMap
probably 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
BTreeMap
actually 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
BTreeMap
and 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 23 2024 at 12:05 UTC