-
Notifications
You must be signed in to change notification settings - Fork 335
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
perf: improve to_file_path() #1018
base: main
Are you sure you want to change the base?
Conversation
} else { | ||
Vec::new() | ||
}; | ||
let mut bytes = Vec::with_capacity(estimated_capacity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before 1,000 iterations within an iteration:
test url_to_file_path ... bench: 202,125 ns/iter (+/- 12,207)
After:
test url_to_file_path ... bench: 127,257 ns/iter (+/- 4,782)
host: Option<&str>, | ||
segments: str::Split<char>, | ||
) -> Result<PathBuf, ()> { | ||
file_url_segments_to_pathbuf_windows(host, segments) | ||
file_url_segments_to_pathbuf_windows(estimated_capacity, host, segments) | ||
} | ||
|
||
// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102 | ||
#[cfg(feature = "std")] | ||
#[cfg_attr(not(windows), allow(dead_code))] | ||
fn file_url_segments_to_pathbuf_windows( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before 1000 iterations within an iteration:
test url_to_file_path ... bench: 437,555 ns/iter (+/- 11,519)
After:
test url_to_file_path ... bench: 119,461 ns/iter (+/- 5,927)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1018 +/- ##
=======================================
Coverage ? 80.32%
=======================================
Files ? 24
Lines ? 4233
Branches ? 0
=======================================
Hits ? 3400
Misses ? 833
Partials ? 0 ☔ View full report in Codecov by Sentry. |
Opened #1019 for the CI. |
Reduces some heap allocations and pre-allocates the vector for building the string.