-
Notifications
You must be signed in to change notification settings - Fork 27
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
[Experiment] Use coresimd, runtime feature detection and a faster, shorter algorithm #37
Conversation
You're welcome!
It appears that we've successfully raced to the bottom - impressive work! |
Why not add this as an experimental feature that overrides the others when present, say |
I would definitely use this. It would motivate me to switch One thing to be cautious of though is that coresimd is still evolving, so switching to it will likely increase the maintenance burden until it settles down. |
Yeah, coresimd 0.0.4 has no effortless upgrade path at the moment, and uses some deprecated features. Hopefully we'll have that resolved by the end of the year - it looks like all you'll need to do is change some type definitions and function calls. |
For detailed performance numbers, see the charts. The graphs are on the SIMD and AVX tabs. Note that the SIMD variant was used without If @BurntSushi's going to use this, I think it's worthwhile doing. My main concern is just having something for the stable channel. |
We can still use the old bit-twiddling algorithms on anything but nightly. Then it's a matter of using a feature, as we've done all the time. I think we even might want to keep the |
I am not particularly eager to simultaneously support |
You're right. |
I've been meaning to speak with the Also, it may be worth looking into potential performance difference on non-x86 targets. |
I have a few ARMs here; nothing fancy, just an Android phone and a RasPii 1&2. |
I hope to convert the regex library over to this soon. This means dropping the |
@BurntSushi I might prefer to wait for the platform independent variants to appear, depending on how long they will take, before tearing out the current support. It is my understanding that those are planned to be added to Rust directly. A short interim period where you use the SIMD-less fallback wouldn't bother me much TBH, as long as it stays short. I suppose you have a much better intuition about timescales than I do. If you'd rather push forward with more immediacy, I guess that is fine too. I would probably only bother supporting an x86 fast-path directly, though. |
I do believe the current approximate plan is to bring in the portable API to But yeah, I don't know when exactly I'll work on porting the regex crate. It is pretty hairy stuff and will likely take me some time. When that drops, I'll basically just move forward with shipping portable binaries, but I'll leave the
Yes, that is my plan as well. For my uses on text, a portable API is insufficient anyway, so I'd have to write different algorithms for each platform depending on what intrinsics are available to me. I don't personally plan on doing that for anything but |
@Veedrac I forgot that the portable API is actually part of nightly too: https://doc.rust-lang.org/nightly/std/simd/ --- Does that change your calculus at all? (The portable API hasn't gone through an RFC yet, so it may be subject to revision more so than the vendor dependent APIs, but it is very similar to what the |
Thanks for pointing that out, that seems like at least enough reason to port this patch and get a foot in the door. |
|
No sure either. I guess the first question to ask is whether you're OK with having an optional dependency on std? |
I'd hesitate to pessimise our |
Is there a reason for leaving |
@llogiq Are you asking why |
@Veedrac See: https://github.com/rust-lang/rfcs/blob/master/text/2325-stable-simd.md#the-is_target_feature_detected-macro --- TL;DR it wasn't an oversight, and while it is possible to do, we took the conservative route for now. I think the thing I'm after is whether you're willing to support a |
Thanks for the link. Doesn't that justification weaken now that we're going with Supporting a |
@Veedrac Possibly, yes. I'm not sure what you mean by unfair though. It's unfair from the context of what Rust supports, sure, maybe. But |
I meant in comparison to the |
Can't we do both? The interface is pretty similar, and I think we should be able to create an abstraction over both The downside is of course that the underlying implementation may change, and we'd have to update accordingly. I think that would be worth it. |
The newest patch splits the code up into different folders so it's less of a single congealed mess. I've got two features; I think using the As it stands I think I'm just going to add some fake vector support for stable users, run a few tests and call it a day. E: Done. |
bb1354c
to
f93b6a6
Compare
Are there plans to revive this PR now when Rust 1.27 with SIMD was released? |
@mati865 Yep, just been distracted by work and other interests. Only issue is I don't think @BurntSushi tracks the newest stable, and he's our major customer. |
@Veedrac Right, yeah. If you increase the minimum Rust version to 1.27 that would be fine, but I probably wouldn't upgrade to it for at least a few release cycles. The only other alternative is to provide automatic and optional support for 1.27 but still work on older Rust releases (which probably either implies a performance regression or more work maintaining alternative fast implementations or maybe even both, I don't know). Up to y'all! I can be patient. |
I've locally rebased this to bring in criterion benchmarks. We lose against the naive algorithm until ~12 bytes on my machine, at which point the hyper versions become consistently faster. |
Ju wanted to point out somewhere. We (Fedora), love ripgrep and we can't use its full power because we use stable compiler (so no "simd" crate). It would be nice if we could move this forward. |
@ignatenkobrain As I understand it, making progress on this soon might entail a pretty big maintenance burden that we shouldn't expect folks to entertain. We might just need to wait until ripgrep can make Rust 1.27 its minimum version (which, realistically, is maybe ~6 months from now). A possible alternative path is to cut a |
Fedora has 1.27.2 |
@ignatenkobrain If you want to run a patched ripgrep I'll bump this up in priority. |
@Veedrac that would be nice. I can patch fedora's ripgrep to use this. |
In light of BurntSushi/ripgrep#1019, I switched ripgrep's minimum supported Rust version to "latest" stable, so feel free to move forward with this whenever. :-) |
@BurntSushi Exciting. I'll have a patch out this week, since I finally have a free weekend. |
A new try for stable is going on here: #44. Closing this PR. |
I tried writing this with
coresimd
. Turns out we can do a lot better;Note that coresimd isn't settled and this doesn't build on stable, so it needs some work to become an actual competitor. I also think the
target_feature
stuff is suboptimal, since it's not applied in places where it could be, and we'd probably be better off if we detected AVX at runtime as well.Thanks /u/vvimpcrvsh for writing up a trick that I used here and that encouraged me to bother with this experiment.