Update Wasmer, log load times, some minor performance tweaks
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
f4d09a8915
commit
055fbfba78
|
@ -1,3 +1,6 @@
|
||||||
[target.x86_64-unknown-linux-gnu]
|
[target.x86_64-unknown-linux-gnu]
|
||||||
linker = "/usr/bin/clang"
|
linker = "/usr/bin/clang"
|
||||||
rustflags = ["-Clink-arg=-fuse-ld=/usr/bin/mold"]
|
rustflags = ["-Clink-arg=-fuse-ld=/usr/bin/mold"]
|
||||||
|
|
||||||
|
[rust]
|
||||||
|
debuginfo-level = 1
|
|
@ -53,7 +53,7 @@ hashbrown = "0.13.1"
|
||||||
indexmap = "1.8.2"
|
indexmap = "1.8.2"
|
||||||
parking_lot = "0.12.1"
|
parking_lot = "0.12.1"
|
||||||
serde = { version = "1.0.137", optional = true, features = ["derive"] }
|
serde = { version = "1.0.137", optional = true, features = ["derive"] }
|
||||||
wasmer = { version = "3.0.1", optional = true, default-features = true }
|
wasmer = { version = "3.1.0", optional = true, default-features = false, features = ["sys", "wat", "llvm"] }
|
||||||
uuid = "1.2.2"
|
uuid = "1.2.2"
|
||||||
paste = { version = "1.0.8" }
|
paste = { version = "1.0.8" }
|
||||||
arcstr = { version = "1.1.4", features = ["std"] }
|
arcstr = { version = "1.1.4", features = ["std"] }
|
||||||
|
|
|
@ -7,8 +7,8 @@ use hashbrown::{HashMap, HashSet};
|
||||||
use parking_lot::lock_api::RwLockReadGuard;
|
use parking_lot::lock_api::RwLockReadGuard;
|
||||||
use parking_lot::{RawRwLock, RwLock};
|
use parking_lot::{RawRwLock, RwLock};
|
||||||
use wasmer::{
|
use wasmer::{
|
||||||
AsStoreMut, AsStoreRef, Cranelift, EngineBuilder, Extern, Features, Function, FunctionEnv, Imports, Instance,
|
AsStoreMut, AsStoreRef, EngineBuilder, Extern, Features, Function, FunctionEnv, Imports, Instance, Memory, Module,
|
||||||
Memory, Module, Store, StoreMut, StoreRef, TypedFunction, Value,
|
Store, StoreMut, StoreRef, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::dynamic_data::{ItemScript, Script, ScriptOwnerData, ScriptResolver};
|
use crate::dynamic_data::{ItemScript, Script, ScriptOwnerData, ScriptResolver};
|
||||||
|
@ -52,7 +52,7 @@ struct ScriptCapabilitiesKey {
|
||||||
impl WebAssemblyScriptResolver {
|
impl WebAssemblyScriptResolver {
|
||||||
/// Instantiates a new WebAssemblyScriptResolver.
|
/// Instantiates a new WebAssemblyScriptResolver.
|
||||||
pub fn new() -> Box<WebAssemblyScriptResolver> {
|
pub fn new() -> Box<WebAssemblyScriptResolver> {
|
||||||
let compiler = Cranelift::default();
|
let compiler = wasmer::LLVM::default();
|
||||||
let mut features = Features::new();
|
let mut features = Features::new();
|
||||||
features.multi_value = true;
|
features.multi_value = true;
|
||||||
features.reference_types = true;
|
features.reference_types = true;
|
||||||
|
|
|
@ -129,10 +129,13 @@ impl ValueIdentifiable for StringKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The difference in ascii characters to translate from uppercase to lowercase.
|
||||||
|
const CAPITAL_DIFF: u8 = b'a' - b'A';
|
||||||
|
|
||||||
/// Converts a character to lowercased in a const safe way.
|
/// Converts a character to lowercased in a const safe way.
|
||||||
const fn to_lower(c: u8) -> u8 {
|
const fn to_lower(c: u8) -> u8 {
|
||||||
if c >= b'A' && c <= b'Z' {
|
if c >= b'A' && c <= b'Z' {
|
||||||
return c + (b'a' - b'A');
|
return c + CAPITAL_DIFF;
|
||||||
}
|
}
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use chrono::Duration;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -24,18 +25,45 @@ use pkmn_lib::static_data::{
|
||||||
};
|
};
|
||||||
use pkmn_lib::StringKey;
|
use pkmn_lib::StringKey;
|
||||||
|
|
||||||
pub fn load_library() -> Arc<dyn DynamicLibrary> {
|
pub struct LoadResult {
|
||||||
|
pub library: Arc<dyn DynamicLibrary>,
|
||||||
|
pub types_load_time: Duration,
|
||||||
|
pub natures_load_time: Duration,
|
||||||
|
pub items_load_time: Duration,
|
||||||
|
pub growth_rate_load_time: Duration,
|
||||||
|
pub abilities_load_time: Duration,
|
||||||
|
pub moves_load_time: Duration,
|
||||||
|
pub species_load_time: Duration,
|
||||||
|
pub wasm_load_time: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_library() -> LoadResult {
|
||||||
let mut path = get_project_root().unwrap();
|
let mut path = get_project_root().unwrap();
|
||||||
path.push("tests/data/");
|
path.push("tests/data/");
|
||||||
let path = path.to_str().unwrap().to_string();
|
let path = path.to_str().unwrap().to_string();
|
||||||
|
|
||||||
|
let t1 = chrono::Utc::now();
|
||||||
let types = load_types(&path);
|
let types = load_types(&path);
|
||||||
|
let t2 = chrono::Utc::now();
|
||||||
|
let types_load_time = t2 - t1;
|
||||||
let natures = load_natures(&path);
|
let natures = load_natures(&path);
|
||||||
|
let t1 = chrono::Utc::now();
|
||||||
|
let natures_load_time = t1 - t2;
|
||||||
let items = load_items(&path);
|
let items = load_items(&path);
|
||||||
|
let t2 = chrono::Utc::now();
|
||||||
|
let items_load_time = t2 - t1;
|
||||||
let growth_rates = load_growth_rates(&path);
|
let growth_rates = load_growth_rates(&path);
|
||||||
|
let t1 = chrono::Utc::now();
|
||||||
|
let growth_rate_load_time = t1 - t2;
|
||||||
let abilities = load_abilities(&path);
|
let abilities = load_abilities(&path);
|
||||||
|
let t2 = chrono::Utc::now();
|
||||||
|
let abilities_load_time = t2 - t1;
|
||||||
let moves = load_moves(&path, &types);
|
let moves = load_moves(&path, &types);
|
||||||
|
let t1 = chrono::Utc::now();
|
||||||
|
let moves_load_time = t1 - t2;
|
||||||
let species = load_species(&path, &types, &moves);
|
let species = load_species(&path, &types, &moves);
|
||||||
|
let t2 = chrono::Utc::now();
|
||||||
|
let species_load_time = t2 - t1;
|
||||||
|
|
||||||
let data = StaticDataImpl::new(
|
let data = StaticDataImpl::new(
|
||||||
Box::new(LibrarySettingsImpl::new(100)),
|
Box::new(LibrarySettingsImpl::new(100)),
|
||||||
|
@ -47,16 +75,32 @@ pub fn load_library() -> Arc<dyn DynamicLibrary> {
|
||||||
natures,
|
natures,
|
||||||
abilities,
|
abilities,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let t1 = chrono::Utc::now();
|
||||||
let mut resolver = WebAssemblyScriptResolver::new();
|
let mut resolver = WebAssemblyScriptResolver::new();
|
||||||
load_wasm(&path, resolver.as_mut());
|
load_wasm(&path, resolver.as_mut());
|
||||||
|
let t2 = chrono::Utc::now();
|
||||||
|
let wasm_load_time = t2 - t1;
|
||||||
|
|
||||||
Arc::new(DynamicLibraryImpl::new(
|
let library = Arc::new(DynamicLibraryImpl::new(
|
||||||
Box::new(data),
|
Box::new(data),
|
||||||
Box::new(Gen7BattleStatCalculator::new()),
|
Box::new(Gen7BattleStatCalculator::new()),
|
||||||
Box::new(Gen7DamageLibrary::new(false)),
|
Box::new(Gen7DamageLibrary::new(false)),
|
||||||
Box::new(Gen7MiscLibrary::new()),
|
Box::new(Gen7MiscLibrary::new()),
|
||||||
resolver,
|
resolver,
|
||||||
))
|
));
|
||||||
|
|
||||||
|
LoadResult {
|
||||||
|
library,
|
||||||
|
types_load_time,
|
||||||
|
natures_load_time,
|
||||||
|
items_load_time,
|
||||||
|
growth_rate_load_time,
|
||||||
|
abilities_load_time,
|
||||||
|
moves_load_time,
|
||||||
|
species_load_time,
|
||||||
|
wasm_load_time,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_types(path: &String) -> Box<dyn TypeLibrary> {
|
pub fn load_types(path: &String) -> Box<dyn TypeLibrary> {
|
||||||
|
|
|
@ -19,16 +19,35 @@ use crate::common::{library_loader, TestCase};
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
fn get_library() -> Arc<dyn DynamicLibrary> {
|
fn get_library() -> Arc<dyn DynamicLibrary> {
|
||||||
library_loader::load_library()
|
library_loader::load_library().library
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore)]
|
|
||||||
fn validate_library_load() {
|
fn validate_library_load() {
|
||||||
let start_time = chrono::Utc::now();
|
let start_time = chrono::Utc::now();
|
||||||
library_loader::load_library();
|
let result = library_loader::load_library();
|
||||||
let end_time = chrono::Utc::now();
|
let end_time = chrono::Utc::now();
|
||||||
println!("Built library in {} ms", (end_time - start_time).num_milliseconds());
|
println!(
|
||||||
|
"Built library in {} ms\
|
||||||
|
\n\t- Types load time: {} ms\
|
||||||
|
\n\t- Natures load time: {} ms\
|
||||||
|
\n\t- Items load time: {} ms\
|
||||||
|
\n\t- Growth Rate load time: {} ms\
|
||||||
|
\n\t- Abilities load time: {} ms\
|
||||||
|
\n\t- Moves load time: {} ms\
|
||||||
|
\n\t- Species load time: {} ms\
|
||||||
|
\n\t- WASM load time: {} ms\
|
||||||
|
",
|
||||||
|
(end_time - start_time).num_milliseconds(),
|
||||||
|
result.types_load_time.num_milliseconds(),
|
||||||
|
result.natures_load_time.num_milliseconds(),
|
||||||
|
result.items_load_time.num_milliseconds(),
|
||||||
|
result.growth_rate_load_time.num_milliseconds(),
|
||||||
|
result.abilities_load_time.num_milliseconds(),
|
||||||
|
result.moves_load_time.num_milliseconds(),
|
||||||
|
result.species_load_time.num_milliseconds(),
|
||||||
|
result.wasm_load_time.num_milliseconds(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[datatest::files("tests/test_cases", {
|
#[datatest::files("tests/test_cases", {
|
||||||
|
|
Loading…
Reference in New Issue