Commit ec9b62a
Enable borrowing components and stores mutable at the same time (#11987)
* Use `OptionsIndex` more internally in components
This updates various runtimes bits for components to use `OptionsIndex`
more aggressively and ultimately deletes the old `Options` type. The
`Options` type is a heavyweight package of all possible options which is
effectively a duplication of what `OptionsIndex` points to, so that's
removed in favor of directly accessing options.
* Enable borrowing components and stores mutable at the same time
This commit adds a new, safe, function to the `Instance` type for
internal use in Wasmtime which enables simultaneously borrowing the
`Component`-within-the-`Instance` as well as the original store at the
same time. This is not possible to do in safe Rust when the store is
mutable and must be implemented with `unsafe` code.
The motivation for this commit is performance. In #11974 it was
discovered that the addition of a single `Arc::clone` was enough to
reduce throughput in the embedding by 20%. While `Arc::clone` is
generally cheap I can see how a "contended" `Arc::clone` could get quite
expensive. This particular benchmark was running multiple instances of
the same component across multiple threads which were all doing many
host calls. Each host call, after the refactoring of #10959, contained
an `Arc::clone` to the component itself. This in turn led to many
threads constantly incrementing/decrementing the `Arc::clone` count of
the same `Arc` instance.
At a high level this clone is not necessary. The component lives within
the store and cannot be mutated/deleted during execution. Safe Rust,
however, forbids access to the component and mutably using the store at
the same time. Thus, this helper function enters the picture. The goal
here is to remove the `Arc::clone` calls without requiring major surgery
or such to refactor the implementations of various functions throughout
Wasmtime. The `unsafe` block used to implement this function documents
more rationale as to why this should be safe.
* Update crates/wasmtime/src/runtime/component/instance.rs
Co-authored-by: Nick Fitzgerald <[email protected]>
---------
Co-authored-by: Nick Fitzgerald <[email protected]>1 parent d5ef528 commit ec9b62a
File tree
10 files changed
+370
-367
lines changed- crates
- environ/src/component
- wasmtime/src/runtime
- component
- concurrent
- func
- vm
10 files changed
+370
-367
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
543 | 553 | | |
544 | 554 | | |
545 | 555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
2603 | 2603 | | |
2604 | 2604 | | |
2605 | 2605 | | |
2606 | | - | |
| 2606 | + | |
2607 | 2607 | | |
2608 | 2608 | | |
2609 | 2609 | | |
| |||
3159 | 3159 | | |
3160 | 3160 | | |
3161 | 3161 | | |
3162 | | - | |
3163 | | - | |
3164 | | - | |
3165 | | - | |
3166 | | - | |
3167 | | - | |
3168 | | - | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
3169 | 3167 | | |
3170 | 3168 | | |
3171 | 3169 | | |
| |||
4902 | 4900 | | |
4903 | 4901 | | |
4904 | 4902 | | |
| 4903 | + | |
4905 | 4904 | | |
4906 | 4905 | | |
4907 | | - | |
4908 | | - | |
4909 | | - | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
4910 | 4912 | | |
4911 | 4913 | | |
4912 | 4914 | | |
| |||
5012 | 5014 | | |
5013 | 5015 | | |
5014 | 5016 | | |
5015 | | - | |
| 5017 | + | |
5016 | 5018 | | |
| 5019 | + | |
5017 | 5020 | | |
5018 | 5021 | | |
5019 | | - | |
5020 | 5022 | | |
| 5023 | + | |
| 5024 | + | |
| 5025 | + | |
| 5026 | + | |
5021 | 5027 | | |
5022 | 5028 | | |
5023 | 5029 | | |
| |||
5039 | 5045 | | |
5040 | 5046 | | |
5041 | 5047 | | |
5042 | | - | |
| 5048 | + | |
5043 | 5049 | | |
5044 | 5050 | | |
5045 | 5051 | | |
| |||
0 commit comments