Skip to content

Commit

Permalink
feat(autonomi): parallel chunk copy for encrypt
Browse files Browse the repository at this point in the history
Testing on my local machine saved about 18s from 70s of total encrypt
time with a 10GiB file in-memory.
  • Loading branch information
b-zee committed Dec 6, 2024
1 parent 53cbf8d commit 1742772
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 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 autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ hex = "~0.4.3"
libp2p = { git = "https://github.com/maqi/rust-libp2p.git", branch = "kad_0.46.2" }
pyo3 = { version = "0.20", optional = true, features = ["extension-module", "abi3-py38"] }
rand = "0.8.5"
rayon = "1.8.0"
rmp-serde = "1.1.1"
self_encryption = "~0.30.0"
serde = { version = "1.0.133", features = ["derive", "rc"] }
Expand Down
5 changes: 3 additions & 2 deletions autonomi/src/self_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use ant_protocol::storage::Chunk;
use bytes::{BufMut, Bytes, BytesMut};
use rayon::prelude::*;
use self_encryption::{DataMap, MAX_CHUNK_SIZE};
use serde::{Deserialize, Serialize};
use tracing::debug;
Expand Down Expand Up @@ -36,8 +37,8 @@ pub(crate) fn encrypt(data: Bytes) -> Result<(Chunk, Vec<Chunk>), Error> {

// Transform `EncryptedChunk` into `Chunk`
let chunks: Vec<Chunk> = chunks
.into_iter()
.map(|c| Chunk::new(c.content))
.into_par_iter()
.map(|c| Chunk::new(c.content.clone()))
.chain(additional_chunks)
.collect();

Expand Down

0 comments on commit 1742772

Please sign in to comment.