-
Notifications
You must be signed in to change notification settings - Fork 722
[perf] Make an ASCII check faster by enabling the compiler to leverage SIMD instructions #3469
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
base: main
Are you sure you want to change the base?
Conversation
|
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 So I'd like to confirm:
|
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. |
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 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. |
Unfortunately that's not correct. The macOS requirements for
That's also a good idea. There would still be the problem that NIO cannot easily depend on
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:
|
|
Apparently simdutf supports I think Swift takes that into account, so we might not need any changes for the |
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.