-
-
Notifications
You must be signed in to change notification settings - Fork 16
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: cost-free conversion from paths to &str
#93
Conversation
@@ -701,10 +701,10 @@ impl Utf8Path { | |||
/// the current directory. | |||
/// | |||
/// * On Unix, a path is absolute if it starts with the root, so | |||
/// `is_absolute` and [`has_root`] are equivalent. | |||
/// `is_absolute` and [`has_root`] are equivalent. |
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.
Clippy complains if I don't comply to the newly added rule in 1.80.0: https://github.com/camino-rs/camino/actions/runs/10400509135/job/28801185038?pr=93#step:4:150
Thank you for the fantastic contribution! I'd also love to get your benchmark into the repo -- would you be willing to update this PR with it, otherwise is it okay if I pull it in? Using criterion as you've done is great. There is some history here, which is that we previously did pointer casting from |
I would love to! Would you also like to integrate codspeed into the repo? If the answer is a yes, I can add a feature Pre-requisites for codspeed running in GitHub Actions: https://docs.codspeed.io/ci/github-actions |
Thanks again! Will get a release out shortly. |
This is now out in camino 1.1.8. |
Thanks for the help! |
Background:
When I was migrating
PathBuf
toUtf8PathBuf
, etc, I found out some regression in our benchmarks. Then I found outas_str
is actually not cost-free as in the older version of rustc there's no way to get the underlying bytes out of anOsStr
until 1.74.0.In this PR, with the help of
OsStr::as_encoded_bytes
was stabilized in 1.74.0, We can perform a cost-free conversion from&OsStr
to&str
with constraint of it's underlying bytes areUTF-8
encoded.Benchmark:
I did an ad-hoc benchmark with the following code and turned out the time cost is a constant now.
code
Result: