Skip to content

Commit

Permalink
Remove rayon and re-use allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Mar 12, 2024
1 parent af88137 commit cd19735
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ cosmwasm-std = { path = "../std", version = "2.0.0-rc.1", default-features = fal
cosmwasm-crypto = { path = "../crypto", version = "2.0.0-rc.1" }
derivative = "2"
hex = "0.4"
rayon = "1.9.0"
schemars = "0.8.3"
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
serde_json = "1.0.40"
Expand Down
18 changes: 8 additions & 10 deletions packages/vm/src/parsed_wasm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fmt, mem};

use rayon::iter::{IntoParallelIterator, ParallelIterator};
use wasmer::wasmparser::{
BinaryReaderError, CompositeType, Export, FuncToValidate, FunctionBody, Import, MemoryType,
Parser, Payload, TableType, ValidPayload, Validator, ValidatorResources, WasmFeatures,
Expand Down Expand Up @@ -193,16 +192,15 @@ impl<'a> ParsedWasm<'a> {
pub fn validate_funcs(&mut self) -> VmResult<()> {
match self.func_validator {
FunctionValidator::Pending(OpaqueDebug(ref mut funcs)) => {
let result = mem::take(funcs) // This is fine since `Vec::default()` doesn't allocate
.into_par_iter()
.try_for_each(|(func, body)| {
// Reusing the allocations between validations only results in an ~6% performance improvement
// The parallelization is blowing this out of the water by a magnitude of 5x
// Especially when combining this with a high-performance allocator, the missing buffer reuse will be pretty much irrelevant
let mut validator = func.into_validator(Default::default());
let result = (|| {
let mut allocations = <_>::default();
for (func, body) in mem::take(funcs) {
let mut validator = func.into_validator(allocations);
validator.validate(&body)?;
Ok(())
});
allocations = validator.into_allocations();
}
Ok(())
})();

self.func_validator = match result {
Ok(()) => FunctionValidator::Success,
Expand Down

0 comments on commit cd19735

Please sign in to comment.