-
Notifications
You must be signed in to change notification settings - Fork 693
Conditionally const version of strlen #2644
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
Conversation
…version of strlen
included some crap that wasnt meant to be there
fixed feature flags due to multi-arch tests, thanks!
^Seeing 20 failures in CI is not fun haha |
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.
This looks like a very premature optimization to me. It's high-maintenance but low benefit. And specifically:
- Why is it Linux and amd64 only?
- You can't assume that the kernel will always nul-terminate the field. The structure might not even have been written by the kernel.
- Despite all of the fancy SWAR, it's really just reading the d_reclen field. What benefit does all of the SWAR stuff provide, if you assume that d_reclen is valid?
- I'm pretty sure that std::CStr::from_ptr doesn't even do strlen internally. So your complicated function doesn't provide any improvement.
I do not approve of merging this PR.
I'm not sure what it's actually applicable on(architecture wise) I just restrained to the use case as proof of concept. Linux specific is basically because of kernel alignment guarantees, it may apply generally to POSIX, not sure. (Not that I know of any big endian systems on that note too) -Pointless on macos/bsd because of inclusion of d_namelen in struct (IIRC) -You cannot assume d_reclen is valid, that's why I have to purposely detect null padding. I thought a constant function O(1) implementation for a very hot function was interesting at least, so I thought if it was of interest,
|
I'm going to close this however as maybe premature in scope of the generality I guess. Sorry. |
(Firstly, I apologise, this is my first issue on a crate and I wanted to share it, please inform me of etiquette if missed!)
(I VERIFIED ALL TESTS LOCALLY BEFORE PUSHING, ALL WORKED)
What does this PR do
This PR offers an version of strlen for filesystem operations and I believe is
NOTES:
I've changed functions around my the definitions in my own crate, I've exposed the function in this PR as a new function but ideally the function could be placed wherever (it maybe too unsafe to have as a general function)
Even though this is esoteric, this is a very low level thing to optimise, I thing downstream impacts in some cases could be notable.
It needs to be heavily tested to know where it works/what needs to be modified,
I'd like to know simply if the nix maintainers would like this functionality in some form.
my comments are explained in the function definition
PROBLEMS:
Little Endianness, strange edge case versions of unix.
In my crate you can see benchmarks:
https://github.com/alexcu2718/fdf/blob/main/const_str_benchmark.txt
(just clone it and cargo bench)
The benchmarks are pretty impressive,
Checklist:
CONTRIBUTING.md