Skip to content

Commit

Permalink
Use memmap2 in deserialize_from_file
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Dec 14, 2020
1 parent ae7ec9d commit e5a52f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value<T>>` 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

Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions lib/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 4 additions & 2 deletions lib/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,8 +52,9 @@ pub trait Engine {
&self,
file_ref: &Path,
) -> Result<Arc<dyn Artifact>, 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.
Expand Down

0 comments on commit e5a52f1

Please sign in to comment.