perf: cost-free conversion from paths to &str#93
Conversation
| /// | ||
| /// * 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.
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
PathBuftoUtf8PathBuf, etc, I found out some regression in our benchmarks. Then I found outas_stris actually not cost-free as in the older version of rustc there's no way to get the underlying bytes out of anOsStruntil 1.74.0.In this PR, with the help of
OsStr::as_encoded_byteswas stabilized in 1.74.0, We can perform a cost-free conversion from&OsStrto&strwith constraint of it's underlying bytes areUTF-8encoded.Benchmark:
I did an ad-hoc benchmark with the following code and turned out the time cost is a constant now.
code
Result: