diff --git a/CHANGELOG.md b/CHANGELOG.md index d35e464d741..e2dc56dd2e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points` * [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError` * [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64` +* [#1927](https://github.com/wasmerio/wasmer/pull/1927) Added mmap support in `Engine::deserialize_from_file` to speed up artifact loading ### Changed diff --git a/Cargo.lock b/Cargo.lock index d77df4e9ae0..a383d0cf98f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1186,6 +1186,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "memmap2" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b70ca2a6103ac8b665dc150b142ef0e4e89df640c9e6cf295d189c3caebe5a" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.6.1" @@ -2612,6 +2621,7 @@ dependencies = [ "backtrace", "bincode", "lazy_static", + "memmap2", "more-asserts", "rustc-demangle", "serde", diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml index efa4c8f900d..72aa3350f3d 100644 --- a/lib/engine/Cargo.toml +++ b/lib/engine/Cargo.toml @@ -18,6 +18,7 @@ target-lexicon = { version = "0.11", default-features = false } # flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" } backtrace = "0.3" rustc-demangle = "0.1" +memmap2 = "0.1.0" more-asserts = "0.2" thiserror = "1.0" serde = { version = "1.0", features = ["derive", "rc"] } diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index 2828bfc52a3..8cfceb3a83f 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -2,6 +2,7 @@ use crate::tunables::Tunables; use crate::{Artifact, DeserializeError}; +use memmap2::Mmap; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::Arc; @@ -51,8 +52,9 @@ pub trait Engine { &self, file_ref: &Path, ) -> Result, DeserializeError> { - let bytes = std::fs::read(file_ref)?; - self.deserialize(&bytes) + let file = std::fs::File::open(file_ref)?; + let mmap = Mmap::map(&file)?; + self.deserialize(&mmap) } /// A unique identifier for this object.