Skip to content
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

Copy-paste things needed for nearcore#8323 #8792

Merged
merged 5 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions nightly/fuzz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ flags = ["-len_control=0", "-prefer_small=0", "-max_len=4000000"]
# runner = "fuzz_target_1"
# weight = 0
# flags = ["-len_control=0", "-prefer_small=0", "-max_len=4000000"]

[[target]]
crate = "runtime/near-vm/fuzz"
runner = "equivalence_universal"
weight = 0
flags = []

[[target]]
crate = "runtime/near-vm/fuzz"
runner = "metering"
weight = 0
flags = []

[[target]]
crate = "runtime/near-vm/fuzz"
runner = "universal_singlepass"
weight = 0
flags = []
674 changes: 674 additions & 0 deletions runtime/near-vm-runner/src/near_vm_runner.rs

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions runtime/near-vm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
**/target
**/*.rs.bk
.DS_Store
.idea
.gdb_history
**/.vscode
api-docs-repo/
/.cargo_home/
/package/
/dist/
/wapm-cli/
/src/windows-installer/WasmerInstaller.exe
/lib/c-api/wasmer.h

# Generated by tests on Android
/avd
/core
605 changes: 605 additions & 0 deletions runtime/near-vm/ATTRIBUTIONS.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions runtime/near-vm/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-present Wasmer, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions runtime/near-vm/benches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Wasmer Benches

This directory contains small, punctual benches. Other benchmarks are
landing somewhere else. We will update this section soon.
173 changes: 173 additions & 0 deletions runtime/near-vm/benches/limits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use wasmer::*;
use wasmer_engine_universal::UniversalExecutableRef;

pub struct LargeContract {
pub functions: u32,
pub locals_per_function: u32,
pub panic_imports: u32, // How many times to import `env.panic`
}

impl Default for LargeContract {
fn default() -> Self {
Self {
functions: 1,
locals_per_function: 0,
panic_imports: 0,
}
}
}

impl LargeContract {
/// Construct a contract with many entitites.
///
/// Currently supports constructing contracts that contain a specified number of functions with the
/// specified number of locals each.
///
/// Exports a function called `main` that does nothing.
pub fn make(&self) -> Vec<u8> {
use wasm_encoder::{
CodeSection, EntityType, Export, ExportSection, Function, FunctionSection,
ImportSection, Instruction, Module, TypeSection, ValType,
};

// Won't generate a valid WASM without functions.
assert!(
self.functions >= 1,
"must specify at least 1 function to be generated"
);
let mut module = Module::new();
let mut type_section = TypeSection::new();
type_section.function([], []);
module.section(&type_section);

if self.panic_imports != 0 {
let mut import_section = ImportSection::new();
for _ in 0..self.panic_imports {
import_section.import("env", "panic", EntityType::Function(0));
}
module.section(&import_section);
}

let mut functions_section = FunctionSection::new();
for _ in 0..self.functions {
functions_section.function(0);
}
module.section(&functions_section);

let mut exports_section = ExportSection::new();
exports_section.export("main", Export::Function(0));
module.section(&exports_section);

let mut code_section = CodeSection::new();
for _ in 0..self.functions {
let mut f = Function::new([(self.locals_per_function, ValType::I64)]);
f.instruction(&Instruction::End);
code_section.function(&f);
}
module.section(&code_section);

module.finish()
}
}

fn many_functions(c: &mut Criterion) {
let mut group = c.benchmark_group("many_functions");
for functions in [1, 10, 100, 1000, 10000] {
let wasm = LargeContract {
functions,
..Default::default()
}
.make();
let store = Store::new(&Universal::new(Singlepass::new()).engine());
group.bench_function(BenchmarkId::new("compile+instantiate", functions), |b| {
b.iter(|| {
let module = Module::new(&store, &wasm).unwrap();
let imports = imports! {};
let _ = Instance::new(&module, &imports).unwrap();
})
});

let module = Module::new(&store, &wasm).unwrap();
let imports = imports! {};
let instance = Instance::new(&module, &imports).unwrap();
group.bench_function(BenchmarkId::new("lookup_main", functions), |b| {
b.iter(|| {
let _: Function = instance.lookup_function("main").unwrap();
})
});

let main: Function = instance.lookup_function("main").unwrap();
group.bench_function(BenchmarkId::new("call_main", functions), |b| {
b.iter(|| {
black_box(main.call(&[]).unwrap());
})
});

let wasm = wat::parse_bytes(wasm.as_ref()).unwrap();
let executable = store.engine().compile(&wasm, store.tunables()).unwrap();
group.bench_function(BenchmarkId::new("serialize", functions), |b| {
b.iter(|| {
black_box(executable.serialize().unwrap());
})
});

let serialized = executable.serialize().unwrap();
group.bench_function(BenchmarkId::new("load", functions), |b| {
b.iter(|| unsafe {
let deserialized = UniversalExecutableRef::deserialize(&serialized).unwrap();
black_box(store.engine().load(&deserialized).unwrap());
})
});
}
}

fn many_locals(c: &mut Criterion) {
let mut group = c.benchmark_group("many_locals");
for (functions, locals_per_function) in [(10, 100), (100, 1000), (1000, 10000)] {
let wasm = LargeContract {
functions,
locals_per_function,
..Default::default()
}
.make();
let size = functions * locals_per_function;
let store = Store::new(&Universal::new(Singlepass::new()).engine());
group.bench_function(BenchmarkId::new("compile+instantiate", size), |b| {
b.iter(|| {
let module = Module::new(&store, &wasm).unwrap();
let imports = imports! {};
let _ = Instance::new(&module, &imports).unwrap();
})
});

let wasm = wat::parse_bytes(wasm.as_ref()).unwrap();
let executable = store.engine().compile(&wasm, store.tunables()).unwrap();
group.bench_function(BenchmarkId::new("serialize", size), |b| {
b.iter(|| {
black_box(executable.serialize().unwrap());
})
});

let serialized = executable.serialize().unwrap();
group.bench_function(BenchmarkId::new("load", size), |b| {
b.iter(|| unsafe {
let deserialized = UniversalExecutableRef::deserialize(&serialized).unwrap();
black_box(store.engine().load(&deserialized).unwrap());
})
});
}
}

criterion_group! {
name = functions;
config = Criterion::default();
targets = many_functions
}
criterion_group! {
name = locals;
config = Criterion::default();
targets = many_locals
}

criterion_main!(functions, locals);
Loading