Skip to content

Commit

Permalink
Merge #1927
Browse files Browse the repository at this point in the history
1927: Use memmap2 in deserialize_from_file r=syrusakbary a=webmaster128

# Description

As discussed in CosmWasm/cosmwasm#660, we might want to use memmap in deserialize_from_file to speed up artifact loading.

This uses the fork memmap2 because https://rustsec.org/advisories/RUSTSEC-2020-0077.html

~This is based on df3a211 and a CHANGELOG entry is missing, but adding it now for visibility and testing.~

# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Simon Warta <simon@warta.it>
  • Loading branch information
bors[bot] and webmaster128 authored Dec 14, 2020
2 parents 3709c9d + e5a52f1 commit 17752cd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 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
11 changes: 10 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 lib/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2018"

[dependencies]
wasmer = { path = "../api", version = "1.0.0-beta1", default-features = false }
memmap = "0.7"
hex = "0.4"
thiserror = "1"
blake3 = "0.3"
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 17752cd

Please sign in to comment.