Skip to content

Commit 572bb4c

Browse files
perf(snapshots): Parallelize image hashing with rayon (#3250)
1 parent 6d5e8cb commit 572bb4c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Performance
6+
7+
- (snapshots) Parallelize image hashing with rayon ([#3250](https://github.com/getsentry/sentry-cli/pull/3250))
8+
59
### Fixes
610

711
- (sourcemaps) Skip non-base64 embedded sourcemaps during injection ([#3243](https://github.com/getsentry/sentry-cli/pull/3243))

src/commands/build/snapshots.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use console::style;
1111
use itertools::Itertools as _;
1212
use log::{debug, info, warn};
1313
use objectstore_client::{ClientBuilder, ExpirationPolicy, Usecase};
14+
use rayon::prelude::*;
1415
use secrecy::ExposeSecret as _;
1516
use serde_json::Value;
1617
use sha2::{Digest as _, Sha256};
@@ -230,7 +231,7 @@ fn compute_sha256_hash(path: &Path) -> Result<String> {
230231
let mut file = std::fs::File::open(path)
231232
.with_context(|| format!("Failed to open image for hashing: {}", path.display()))?;
232233
let mut hasher = Sha256::new();
233-
let mut buffer = [0u8; 8192];
234+
let mut buffer = [0u8; 65536];
234235
loop {
235236
let bytes_read = file
236237
.read(&mut buffer)
@@ -332,10 +333,17 @@ fn upload_images(
332333
let mut many_builder = session.many();
333334
let mut manifest_entries = HashMap::new();
334335
let mut collisions: HashMap<String, Vec<String>> = HashMap::new();
335-
let mut kept_paths: HashMap<String, String> = HashMap::new();
336-
for image in images {
337-
debug!("Processing image: {}", image.path.display());
336+
let mut kept_paths = HashMap::new();
338337

338+
let hashed_images: Vec<_> = images
339+
.into_par_iter()
340+
.map(|image| {
341+
let hash = compute_sha256_hash(&image.path)?;
342+
Ok((image, hash))
343+
})
344+
.collect::<Result<Vec<_>>>()?;
345+
346+
for (image, hash) in hashed_images {
339347
let image_file_name = image
340348
.relative_path
341349
.file_name()
@@ -353,7 +361,6 @@ fn upload_images(
353361
continue;
354362
}
355363

356-
let hash = compute_sha256_hash(&image.path)?;
357364
let file = runtime
358365
.block_on(tokio::fs::File::open(&image.path))
359366
.with_context(|| {

0 commit comments

Comments
 (0)