Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write commit time improvements #389

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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