Skip to content

Commit

Permalink
perf(tarball): collect entries into a Vec
Browse files Browse the repository at this point in the history
It improves performance somehow. Probably because a Vec would have a fixed length
which reduces reallocation and resizing of the 2 hashmaps.

Lesson learned: Lazy isn't always good for performance
  • Loading branch information
KSXGitHub committed Nov 4, 2023
1 parent 690d5e1 commit 97237bf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/tarball/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ impl<'a> DownloadTarballToStore<'a> {
.pipe(Cursor::new)
.pipe(Archive::new);

let entries = archive
let entries: Vec<_> = archive
.entries()
.map_err(TarballError::ReadTarballEntries)?
.filter(|entry| !entry.as_ref().unwrap().header().entry_type().is_dir());
.filter(|entry| !entry.as_ref().unwrap().header().entry_type().is_dir())
.collect();

let ((_, Some(capacity)) | (capacity, None)) = entries.size_hint();
let capacity = entries.len();
let mut cas_paths = HashMap::<OsString, PathBuf>::with_capacity(capacity);
let mut pkg_files_idx = PackageFilesIndex { files: HashMap::with_capacity(capacity) };

Expand Down

0 comments on commit 97237bf

Please sign in to comment.