-
Notifications
You must be signed in to change notification settings - Fork 125
refactor(protocol/sandbox): remove store clear counter #5466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ark0f
wants to merge
47
commits into
master
Choose a base branch
from
al/verify-wasmtime-store-clear
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
213f599
Update wasmtime in Substrate
ark0f 4c56ed6
Update wasmtime
ark0f 39ef448
Initial migration to wasmtime
ark0f 0833ef2
Enable winch
ark0f efd836b
Enable caching for embedded executor
ark0f ee40caf
Refactor linker to use MODULE_ENV constant for memory definition
ark0f cf6ead1
Format WASM memory changed message
ark0f 10d2405
Disable mach ports in Wasmtime
ark0f 9d2cc06
Fix clippy warnings
ark0f 5229aaf
Fix deps
ark0f dc82dac
Fix deps
ark0f 78b7290
Merge branch 'master' into al/wasmtime-migration
ark0f 9cb0079
Fix clippy on Windows
ark0f c32ff28
Enable caching in the host executor
ark0f 52e9086
Remove Rust version checks
ark0f b8ff5e8
Improve error handling in `parse_wat` and update `.rodata` naming
ark0f c62f715
Enable Windows testing
ark0f 8208bda
Use Wasmtime caching in embedded executor
ark0f 1297806
Enable caching in authorship tests
ark0f 76f08bc
Enable caching in lazy-pages-fuzzer
ark0f 1c67bc3
Merge branch 'master' into al/wasmtime-migration
ark0f bbcd064
make workspace-hack
ark0f d660c85
Fix sp-application-crypto branch
ark0f 0ef0d66
wasmtime 44.0.1
ark0f ef4395e
Merge remote-tracking branch 'origin/master' into al/wasmtime-migration
ark0f 68ea30e
Fixes after merge
ark0f 63479a5
Remove unused deps
ark0f d97866f
Merge remote-tracking branch 'origin/master' into al/wasmtime-migration
ark0f 20eca80
Fix wat dep removed from calc-stack-height
ark0f bafcffa
Fix wat dep removed from calc-stack-height
ark0f d936166
Add gear-workspace-hack to sandbox dependencies
ark0f b99da05
Fix embedded executor
ark0f 94a9a9f
Merge remote-tracking branch 'origin/master' into al/wasmtime-migration
ark0f 438a070
Update workspace hack
ark0f a0f8a9a
Remove obsolete cargo-shear metadata
ark0f de8e7a2
Remove unused gear-wasmtime-cache dependency
ark0f 033a293
Remove unused pathdiff dependency and cleanup authorship module
ark0f 3867fea
Remove unused sandbox build script
ark0f 4ff6164
Clarify comments and signal handling logic in lazy-pages Unix impleme…
ark0f d1b32dd
Resolve TODOs
ark0f bf565d6
Update mach2
ark0f 58d15a3
Justify `macos_use_mach_ports` usage
ark0f 671663f
Update instruction weights estimation
ark0f db31a85
refactor(vara): benchmark Wasmtime store growth
ark0f 6013fd6
Merge remote-tracking branch 'origin/master' into al/verify-wasmtime-…
ark0f 8d6b65a
chore: fix benchmark license header
ark0f 5b3829b
test: remove redundant sandbox init test
ark0f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| // Copyright (C) Gear Technologies Inc. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| use criterion::{Criterion, criterion_group, criterion_main}; | ||
| use gear_sandbox_env::{EnvironmentDefinition, Instantiate}; | ||
| use gear_sandbox_host::{ | ||
| context::{HostResult, SupervisorContext, SupervisorContextDispatcher, SupervisorFuncIndex}, | ||
| sandbox::{GuestEnvironment, SandboxBackend, SandboxComponents}, | ||
| }; | ||
| use parity_scale_codec::Encode; | ||
| use sp_wasm_interface_common::{Pointer, WordSize}; | ||
| use std::{ | ||
| hint::black_box, | ||
| time::{Duration, Instant}, | ||
| }; | ||
|
|
||
| const EMPTY_WASM: &[u8] = b"\0asm\x01\0\0\0"; | ||
| const MAX_OPERATIONS_PER_STORE: u64 = | ||
| (wasmtime::DEFAULT_INSTANCE_LIMIT as u64 + wasmtime::DEFAULT_MEMORY_LIMIT as u64) / 2; | ||
|
|
||
| #[derive(Clone, Copy)] | ||
| enum ResetPolicy { | ||
| Never, | ||
| Every(usize), | ||
| } | ||
|
|
||
| impl ResetPolicy { | ||
| fn as_str(self) -> &'static str { | ||
| match self { | ||
| Self::Never => "long_lived_store", | ||
| Self::Every(_) => "clear_periodically", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct NoopSupervisor; | ||
|
|
||
| impl SupervisorContext for NoopSupervisor { | ||
| fn data_ptr(&self) -> *const () { | ||
| self as *const _ as *const () | ||
| } | ||
|
|
||
| fn read_memory_into( | ||
| &self, | ||
| _address: Pointer<u8>, | ||
| dest: &mut [u8], | ||
| ) -> std::result::Result<(), String> { | ||
| dest.fill(0); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn write_memory( | ||
| &mut self, | ||
| _address: Pointer<u8>, | ||
| _data: &[u8], | ||
| ) -> std::result::Result<(), String> { | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn allocate_memory(&mut self, _size: WordSize) -> std::result::Result<Pointer<u8>, String> { | ||
| Ok(Pointer::null()) | ||
| } | ||
|
|
||
| fn deallocate_memory(&mut self, _ptr: Pointer<u8>) -> std::result::Result<(), String> { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl SupervisorContextDispatcher for NoopSupervisor { | ||
| fn dispatch_thunk_id(&self) -> u32 { | ||
| 0 | ||
| } | ||
|
|
||
| fn invoke( | ||
| &mut self, | ||
| _invoke_args_ptr: Pointer<u8>, | ||
| _invoke_args_len: WordSize, | ||
| _func_idx: SupervisorFuncIndex, | ||
| ) -> HostResult<i64> { | ||
| Ok(0) | ||
| } | ||
| } | ||
|
|
||
| fn bench_wasmtime_store_growth(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("wasmtime_store_growth"); | ||
|
|
||
| for reset_policy in [ResetPolicy::Never, ResetPolicy::Every(50)] { | ||
| group.bench_function(reset_policy.as_str(), |b| { | ||
| b.iter_custom(|iters| { | ||
| let mut state = BenchState::new(); | ||
| let mut elapsed = Duration::ZERO; | ||
| for i in 0..iters { | ||
| if i.is_multiple_of(MAX_OPERATIONS_PER_STORE) { | ||
|
ark0f marked this conversation as resolved.
|
||
| state = BenchState::new(); | ||
| } | ||
|
|
||
| let instant = Instant::now(); | ||
| state.run_iteration(i, reset_policy); | ||
| elapsed += instant.elapsed(); | ||
| } | ||
| elapsed | ||
| }) | ||
| }); | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| struct BenchState { | ||
| store: SandboxComponents, | ||
| env_def: Vec<u8>, | ||
| supervisor: NoopSupervisor, | ||
| } | ||
|
|
||
| impl BenchState { | ||
| fn new() -> Self { | ||
| Self { | ||
| store: SandboxComponents::new(SandboxBackend::Wasmtime), | ||
| env_def: EnvironmentDefinition { | ||
| entries: Vec::new(), | ||
| } | ||
| .encode(), | ||
| supervisor: NoopSupervisor, | ||
| } | ||
| } | ||
|
|
||
| fn run_iteration(&mut self, iteration: u64, reset_policy: ResetPolicy) { | ||
| let memory_idx = self | ||
| .store | ||
| .new_memory(1, 1) | ||
| .expect("failed to create sandbox memory"); | ||
| black_box(memory_idx); | ||
|
|
||
| let guest_env = GuestEnvironment::decode(&self.store, &self.env_def) | ||
| .unwrap_or_else(|_| panic!("failed to decode env")); | ||
| let instance = self | ||
| .store | ||
| .instantiate( | ||
| Instantiate::Version1, | ||
| EMPTY_WASM, | ||
| guest_env, | ||
| &mut self.supervisor, | ||
| ) | ||
| .unwrap_or_else(|_| panic!("failed to instantiate empty wasm")); | ||
| let instance_idx = instance.register(&mut self.store, self.supervisor.dispatch_thunk_id()); | ||
| black_box(instance_idx); | ||
|
|
||
| if let ResetPolicy::Every(clear_every) = reset_policy | ||
| && iteration.is_multiple_of(clear_every as u64) | ||
| { | ||
| self.store.clear(); | ||
| } | ||
|
ark0f marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_wasmtime_store_growth); | ||
| criterion_main!(benches); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.