Skip to content
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

Remove extra allocation in get_file_paths #237

Merged

Conversation

marxin
Copy link
Contributor

@marxin marxin commented Jul 17, 2024

I was able to measure a difference for debuginfod-rs:

  Time (mean ± σ):      2.303 s ±  0.017 s    [User: 25.220 s, System: 5.214 s]
  Range (min … max):    2.272 s …  2.327 s    10 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: /tmp/after3
  Time (mean ± σ):      2.298 s ±  0.028 s    [User: 24.979 s, System: 5.310 s]
  Range (min … max):    2.241 s …  2.331 s    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  /tmp/after3
    1.00 ± 0.01 times faster than /tmp/before

@@ -770,7 +770,9 @@ impl PackageMetadata {
|mut acc, item| {
let (basename, dir_index) = item;
if let Some(dir) = dirs.get(dir_index as usize) {
acc.push(PathBuf::from(dir).join(basename));
let mut path = PathBuf::from(dir);
path.push(basename);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do Path::from(dir).join(basename) instead? I believe that would also avoid the extra allocation, and perhaps more reliably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, changed!

I was able to measure a difference for debuginfod-rs:

```
  Time (mean ± σ):      2.303 s ±  0.017 s    [User: 25.220 s, System: 5.214 s]
  Range (min … max):    2.272 s …  2.327 s    10 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: /tmp/after3
  Time (mean ± σ):      2.298 s ±  0.028 s    [User: 24.979 s, System: 5.310 s]
  Range (min … max):    2.241 s …  2.331 s    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  /tmp/after3
    1.00 ± 0.01 times faster than /tmp/before
```
@marxin marxin force-pushed the get_file_paths-reduce-PathBuf-allocation branch from ada38bb to 2008114 Compare July 17, 2024 19:14
@dralley dralley merged commit 405e883 into rpm-rs:master Jul 17, 2024
15 checks passed
@marxin marxin deleted the get_file_paths-reduce-PathBuf-allocation branch July 18, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants