| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Thanks for this! I think the idea here is great, but I'm not sure this is the right execution on it. We can plausibly merge it anyway, though I think we should get solid numbers on this specific change before we do so. The reason I'm hesitant is that so far as I can see this does not trigger autovectorization in the compiler. Even passing -target-cpu raptorlake doesn't meaningfully change that. This is as opposed to doing the same function directly on UnsafeRawBufferPointer, where we do see autovec. So I'd like to confirm:
|
Sorry, something went wrong.
No. Good catch. I usually just operate on raw bytes so did not notice this doesn't work directly on a UTF8View.
Yes I guess Swift could have something similar to https://github.com/simdutf/simdutf.
Yes that's the solution although it does look a bit ugly. |
Sorry, something went wrong.
I'd be inclined to say that you'd offer two variations of each method, one based on raw pointers and one on spans. NIO will be able to rely entirely on spans in relatively short order: when Swift 6.4 ships, Swift 6.2 will become our floor and we can then rely entirely on Span-taking APIs. In fact, if we wanted to really go down this road of thought exercise: should the thing we're discussing just be simdutf? If someone (nudge nudge) wanted to engage with the simdutf folks about whether they were interested in adopting the __counted_by and __noescape flags, then conceptually C++ interop gets the rest of the way to a useful Swift package that basically just makes simdutf available. Unfortunately, simdutf doesn't offer the specific algorithm I was hoping to find (a vectorized case-insensitive ASCII comparison), so some custom work would still be necessary, which again raises the question of whether we should write something specifically for this use-case for us. |
Sorry, something went wrong.
Unfortunately that's not correct. The macOS requirements for Span will still be too high.
That's also a good idea. There would still be the problem that NIO cannot easily depend on Span.
Perhaps they'll be fine with adding such a function, assuming it really does not exist. A case-insensitive ASCII check is pretty common. EDIT: Previously this post also contained this, which is fake news and should be disregarded: I had not taken a look at the code on machines with amd architecture. Apparently the auto-vectorization only kicks in on arm machines for some reason (We'll still need to access some kind of trivial form of the string, such as with accessing the pointer of bytes directly). |
Sorry, something went wrong.
|
Apparently simdutf supports std::span: I think Swift takes that into account, so we might not need any changes for the Span support: |
Sorry, something went wrong.
Sorry, something went wrong.
|
Related discussion: https://forums.swift.org/t/making-simdutf-c-c-seamlessly-interoperate-with-swift/83940 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Motivation:
Faster code.
Modifications:
Turn the "isASCII" check into simple a simple bitwise operation in a loop, which enables the compiler to compile the code into SIMD instructions, and in-turn make the code faster.
I did a quick check to have some numbers before I propose this PR; looks like this is a ~400x improvement even for small strings of 5 bytes.
Result:
Faster code.