Skip to content

Commit

Permalink
Merge pull request #389 from dusk-network/commit-time-optimisation
Browse files Browse the repository at this point in the history
Write commit time improvements
  • Loading branch information
miloszm authored Sep 30, 2024
2 parents 421a0a3 + c9e14dc commit 5d6dd63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 2 additions & 0 deletions piecrust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Improved commit writing time [#388]
- Changed state representation to improve commit performance [#342]

## [0.24.0] - 2024-09-04
Expand Down Expand Up @@ -465,6 +466,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- ISSUES -->

[#388]: https://github.com/dusk-network/piecrust/issues/388
[#371]: https://github.com/dusk-network/piecrust/issues/371
[#359]: https://github.com/dusk-network/piecrust/issues/359
[#357]: https://github.com/dusk-network/piecrust/issues/357
Expand Down
26 changes: 12 additions & 14 deletions piecrust/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub(crate) enum Call {
Commit {
contracts: BTreeMap<ContractId, ContractDataEntry>,
base: Option<Commit>,
replier: mpsc::SyncSender<io::Result<Commit>>,
replier: mpsc::SyncSender<io::Result<Hash>>,
},
GetCommits {
replier: mpsc::SyncSender<Vec<Hash>>,
Expand Down Expand Up @@ -510,7 +510,7 @@ fn write_commit<P: AsRef<Path>>(
commits: &mut BTreeMap<Hash, Commit>,
base: Option<Commit>,
commit_contracts: BTreeMap<ContractId, ContractDataEntry>,
) -> io::Result<Commit> {
) -> io::Result<Hash> {
let root_dir = root_dir.as_ref();

let mut index = base
Expand All @@ -530,14 +530,14 @@ fn write_commit<P: AsRef<Path>>(

// Don't write the commit if it already exists on disk. This may happen if
// the same transactions on the same base commit for example.
if let Some(commit) = commits.get(&root) {
return Ok(commit.clone());
if commits.contains_key(&root) {
return Ok(root);
}

write_commit_inner(root_dir, index, commit_contracts, root_hex, base).map(
|commit| {
commits.insert(root, commit.clone());
commit
commits.insert(root, commit);
root
},
)
}
Expand Down Expand Up @@ -622,14 +622,12 @@ fn write_commit_inner<P: AsRef<Path>, S: AsRef<str>>(
}

let index_main_path = index_path_main(directories.main_dir, commit_id)?;
let index_bytes = rkyv::to_bytes::<_, 128>(&index)
.map_err(|err| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Failed serializing index file: {err}"),
)
})?
.to_vec();
let index_bytes = rkyv::to_bytes::<_, 128>(&index).map_err(|err| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Failed serializing index file: {err}"),
)
})?;
fs::write(index_main_path.clone(), index_bytes)?;

Ok(Commit { index })
Expand Down
1 change: 0 additions & 1 deletion piecrust/src/store/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ impl ContractSession {
receiver
.recv()
.expect("The receiver should always receive a reply")
.map(|c| *c.index.root())
}

/// Returns path to a file representing a given commit and page.
Expand Down

0 comments on commit 5d6dd63

Please sign in to comment.