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 13, 2020
1 parent 0a1214c commit 6bec8e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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 6bec8e2

Please sign in to comment.