-
Notifications
You must be signed in to change notification settings - Fork 18k
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
cmd/compile: emit optimized assembly for checking the first chars before {strings|bytes}.IndexByte
call
#25844
Comments
cc'ing @quasilyte and @josharian , since it looks like this may help CLs like https://go-review.googlesource.com/c/go/+/115616 . |
We could also do something similar for HasPrefix and HasSuffix, particularly when the sought byte/prefix/suffix is a constant. However, it seems to me these are perfect candidates for mid-stack or partial inlining, rather than hand-coded compiler optimizations. |
But as I know mid-stack inlining cannot inline yet functions written in assembly |
It is not clear to me what this issue is about. {strings,bytes}.IndexByte already emits handcoded assembly for various platforms. Is this about checking the initial chars before going with the generic algorithm ? What is the heuristic to have 4 as the number ? Why not 3 or 5 ? Or is this about inlining the function calls ? If it is the previous, the difference is very minimal now(smaller than a ns), for the cases where prefix is faster than std. And we already have a special-case assembly when the length of the string is less than 16. So I am not sure if it is worth pursuing to optimize for more corner cases when the attained gain is so less.
@valyala ? |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
The issue
Currently
strings.IndexByte
(andbytes.IndexByte
) call overhead makes these functions slower comparing to a plain check for the first few bytes onamd64
. The following benchmark shows the issue:Benchmark results:
The benchmark shows that the
prefixCheckFunc
outperformsstrings.IndexByte
for short strings and when the required char is located in the short string prefix.Solution
Emit optimized assembly for checking the first chars before
{strings|bytes}.IndexByte
call.This may speed up parsers extracting small tokens such as short numbers, ids and strings.
cc'ing @TocarIP and @randall77 , who may be interested in the implementation.
The text was updated successfully, but these errors were encountered: