This repository was archived by the owner on May 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
[TRY] perf: spawn (parallelize) io tasks related to tarball #190
Closed
Closed
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a195be2
malloc
kdy1 46b4ade
swc_malloc
kdy1 1839714
Dep on rayon
kdy1 8aba776
cargo lockfile
kdy1 af4045d
Dep on num_cpus
kdy1 3297bdb
cargo lockfile
kdy1 3c3166c
Enlarge IO thread pool
kdy1 8662d94
doc
kdy1 8b41c42
Dep on rayon
kdy1 28678b5
cargo lockfile
kdy1 80254ec
Dep on rayon
kdy1 18512c6
cargo lockfile
kdy1 7afc31d
Make writing of cas file happen on other thread
kdy1 6515ebd
Make writing of lazy file happen on other thread
kdy1 23a69f3
chore(git): merge from main
KSXGitHub 4569c7f
fix: clippy
KSXGitHub e93df61
Update crates/tarball/Cargo.toml
kdy1 339b83a
fmt
kdy1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,73 +201,88 @@ impl<'a> DownloadTarballToStore<'a> { | |
| Other(TarballError), | ||
| } | ||
| let cas_paths = tokio::task::spawn(async move { | ||
| verify_checksum(&response, package_integrity.clone()).map_err(TaskError::Checksum)?; | ||
|
|
||
| // TODO: move tarball extraction to its own function | ||
| // TODO: test it | ||
| // TODO: test the duplication of entries | ||
|
|
||
| let mut archive = decompress_gzip(&response, package_unpacked_size) | ||
| .map_err(TaskError::Other)? | ||
| .pipe(Cursor::new) | ||
| .pipe(Archive::new); | ||
|
|
||
| let entries = archive | ||
| .entries() | ||
| .map_err(TarballError::ReadTarballEntries) | ||
| .map_err(TaskError::Other)? | ||
| .filter(|entry| !entry.as_ref().unwrap().header().entry_type().is_dir()); | ||
|
|
||
| let ((_, Some(capacity)) | (capacity, None)) = entries.size_hint(); | ||
| let mut cas_paths = HashMap::<OsString, PathBuf>::with_capacity(capacity); | ||
| let mut pkg_files_idx = PackageFilesIndex { files: HashMap::with_capacity(capacity) }; | ||
|
|
||
| for entry in entries { | ||
| let mut entry = entry.unwrap(); | ||
|
|
||
| let file_mode = entry.header().mode().expect("get mode"); // TODO: properly propagate this error | ||
| let file_is_executable = file_mode::is_all_exec(file_mode); | ||
|
|
||
| // Read the contents of the entry | ||
| let mut buffer = Vec::with_capacity(entry.size() as usize); | ||
| entry.read_to_end(&mut buffer).unwrap(); | ||
|
|
||
| let entry_path = entry.path().unwrap(); | ||
| let cleaned_entry_path = | ||
| entry_path.components().skip(1).collect::<PathBuf>().into_os_string(); | ||
| let (file_path, file_hash) = store_dir | ||
| .write_cas_file(&buffer, file_is_executable) | ||
| .map_err(TarballError::WriteCasFile)?; | ||
|
|
||
| let tarball_index_key = cleaned_entry_path | ||
| .to_str() | ||
| .expect("entry path must be valid UTF-8") // TODO: propagate this error, provide more information | ||
| .to_string(); // TODO: convert cleaned_entry_path to String too. | ||
|
|
||
| if let Some(previous) = cas_paths.insert(cleaned_entry_path, file_path) { | ||
| tracing::warn!(?previous, "Duplication detected. Old entry has been ejected"); | ||
| rayon::scope(|scope| { | ||
| verify_checksum(&response, package_integrity.clone()) | ||
| .map_err(TaskError::Checksum)?; | ||
|
|
||
| // TODO: move tarball extraction to its own function | ||
| // TODO: test it | ||
| // TODO: test the duplication of entries | ||
|
|
||
| let mut archive = decompress_gzip(&response, package_unpacked_size) | ||
| .map_err(TaskError::Other)? | ||
| .pipe(Cursor::new) | ||
| .pipe(Archive::new); | ||
|
|
||
| let entries = archive | ||
| .entries() | ||
| .map_err(TarballError::ReadTarballEntries) | ||
| .map_err(TaskError::Other)? | ||
| .filter(|entry| !entry.as_ref().unwrap().header().entry_type().is_dir()); | ||
|
|
||
| let ((_, Some(capacity)) | (capacity, None)) = entries.size_hint(); | ||
| let mut cas_paths = HashMap::<OsString, PathBuf>::with_capacity(capacity); | ||
| let mut pkg_files_idx = | ||
| PackageFilesIndex { files: HashMap::with_capacity(capacity) }; | ||
|
|
||
| for entry in entries { | ||
| let mut entry = entry.unwrap(); | ||
|
|
||
| let file_mode = entry.header().mode().expect("get mode"); // TODO: properly propagate this error | ||
| let file_is_executable = file_mode::is_all_exec(file_mode); | ||
|
|
||
| // Read the contents of the entry | ||
| let mut buffer = Vec::with_capacity(entry.size() as usize); | ||
| entry.read_to_end(&mut buffer).unwrap(); | ||
|
|
||
| let entry_path = entry.path().unwrap(); | ||
| let cleaned_entry_path = | ||
| entry_path.components().skip(1).collect::<PathBuf>().into_os_string(); | ||
| let (file_path, file_hash) = store_dir | ||
| .write_cas_file(scope, buffer, file_is_executable) | ||
| .map_err(TarballError::WriteCasFile)?; | ||
|
Comment on lines
+234
to
+236
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be the only IO operation in the entire scope. And none of the operations that follow depend on this IO operation being done either. Meaning, we could potentially defer this operation after building the |
||
|
|
||
| let tarball_index_key = cleaned_entry_path | ||
| .to_str() | ||
| .expect("entry path must be valid UTF-8") // TODO: propagate this error, provide more information | ||
| .to_string(); // TODO: convert cleaned_entry_path to String too. | ||
|
|
||
| if let Some(previous) = cas_paths.insert(cleaned_entry_path, file_path) { | ||
| tracing::warn!( | ||
| ?previous, | ||
| "Duplication detected. Old entry has been ejected" | ||
| ); | ||
| } | ||
|
|
||
| let checked_at = UNIX_EPOCH.elapsed().ok().map(|x| x.as_millis()); | ||
| let file_size = entry.header().size().ok(); | ||
| let file_integrity = format!("sha512-{}", BASE64_STD.encode(file_hash)); | ||
| let file_attrs = PackageFileInfo { | ||
| checked_at, | ||
| integrity: file_integrity, | ||
| mode: file_mode, | ||
| size: file_size, | ||
| }; | ||
|
|
||
| if let Some(previous) = | ||
| pkg_files_idx.files.insert(tarball_index_key, file_attrs) | ||
| { | ||
| tracing::warn!( | ||
| ?previous, | ||
| "Duplication detected. Old entry has been ejected" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| let checked_at = UNIX_EPOCH.elapsed().ok().map(|x| x.as_millis()); | ||
| let file_size = entry.header().size().ok(); | ||
| let file_integrity = format!("sha512-{}", BASE64_STD.encode(file_hash)); | ||
| let file_attrs = PackageFileInfo { | ||
| checked_at, | ||
| integrity: file_integrity, | ||
| mode: file_mode, | ||
| size: file_size, | ||
| }; | ||
|
|
||
| if let Some(previous) = pkg_files_idx.files.insert(tarball_index_key, file_attrs) { | ||
| tracing::warn!(?previous, "Duplication detected. Old entry has been ejected"); | ||
| } | ||
| } | ||
| scope.spawn(move |_| { | ||
| store_dir | ||
| .write_index_file(&package_integrity, &pkg_files_idx) | ||
| .map_err(TarballError::WriteTarballIndexFile) | ||
| .expect("todo: handle this error"); | ||
| }); | ||
|
|
||
| store_dir | ||
| .write_index_file(&package_integrity, &pkg_files_idx) | ||
| .map_err(TarballError::WriteTarballIndexFile)?; | ||
|
|
||
| Ok(cas_paths) | ||
| Ok(cas_paths) | ||
| }) | ||
| }) | ||
| .await | ||
| .expect("no join error") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.