Repository navigation
perf: stop loading whole files into memory across upload/identify paths #73
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6aa0078
feat(debug-files): --type elf accepts directories of .so files
krassx 7ace775
fix(debug-files): empty ELF directory exits 10; don't descend dir sym…
krassx a741636
fix(debug-files): fail ELF dir scan on any I/O error; harden tests
krassx d7655c5
perf(upload): stream the presigned PUT body and the SHA-1 instead of …
krassx 20a7eb3
perf(elf): memory-map libraries for the identity scan instead of read…
krassx 5dd0fd6
docs(changelog): note the streaming/mmap memory reduction
krassx 7b454ac
perf: stop loading whole files into memory across the upload/identify…
krassx 01e17d9
test(elf): gate the unix-only fixture helper (dead code is an error o…
krassx 1346a32
Merge branch 'feat/elf-directory-input' into perf/stream-uploads-low-…
krassx bdd4794
Merge branch 'perf/stream-uploads-low-memory' into perf/low-memory-audit
krassx 1ab176a
docs(elf): state the mmap contract - directories must not be written …
krassx 362fa0d
Merge perf/stream-uploads-low-memory; fix(dsym): drop the stale 1 GiB…
krassx 0f388c2
fix(upload): follow 307/308 on streamed PUTs ourselves; correct stale…
krassx a870734
Merge remote-tracking branch 'origin/main' into perf/low-memory-audit
krassx 308d4d0
Remove file_chunks re-introduced by the squash merge of #72
krassx 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
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
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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| //! Read-only memory-mapped file bytes, for identity parsing. | ||
| //! | ||
| //! Identifying a debug file (ELF build-id, Mach-O UUID, PDB GUID) touches only | ||
| //! its headers, yet the files are routinely 100+ MB and `std::fs::read` copies | ||
| //! every byte onto the heap. Mapping instead keeps the cost to the pages the | ||
| //! parser actually reads. This is the ONLY place the crate memory-maps a file, so | ||
| //! that `unsafe` lives here (the crate has two other, unrelated `unsafe` uses: the | ||
| //! `fork` in `daemon.rs` and `gethostname` in `build_env.rs`). | ||
|
|
||
| use std::ops::Deref; | ||
| use std::path::Path; | ||
|
|
||
| /// The bytes of a file, mapped read-only (empty for an empty file, which cannot | ||
| /// be mapped). Derefs to `[u8]`. | ||
| pub struct Mapped(Option<memmap2::Mmap>); | ||
|
|
||
| impl Deref for Mapped { | ||
| type Target = [u8]; | ||
| fn deref(&self) -> &[u8] { | ||
| self.0.as_deref().unwrap_or(&[]) | ||
| } | ||
| } | ||
|
|
||
| /// Map `path` read-only. | ||
| /// | ||
| /// Keep the result scoped to the parse and drop it before the file is | ||
| /// rewritten or removed (Windows refuses to replace a mapped file). | ||
| pub fn map_file(path: &Path) -> std::io::Result<Mapped> { | ||
| let file = std::fs::File::open(path)?; | ||
| if file.metadata()?.len() == 0 { | ||
| return Ok(Mapped(None)); | ||
| } | ||
| // SAFETY: the map is read-only. The contract (memmap2's): nothing may truncate | ||
| // or rewrite the file while it is mapped (SIGBUS / undefined behaviour | ||
| // otherwise). It holds for finished build outputs and symbol files, which is all | ||
| // this reads; a file still being written by a linker is not a supported input. | ||
| Ok(Mapped(Some(unsafe { memmap2::Mmap::map(&file) }?))) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn maps_file_contents_and_handles_an_empty_file() { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let p = dir.path().join("f"); | ||
| std::fs::write(&p, b"abc").unwrap(); | ||
| assert_eq!(&*map_file(&p).unwrap(), b"abc"); | ||
| std::fs::write(&p, b"").unwrap(); | ||
| assert!(map_file(&p).unwrap().is_empty()); | ||
| assert!(map_file(&dir.path().join("missing")).is_err()); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.