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
strings: genSplit improvement #18973
Comments
I'm looking into this right now. The CL will be ready soon |
CL https://golang.org/cl/36510 mentions this issue. |
I think the same optimization may be applied to |
Applied the same optimizations to |
Definitely, this can be applied to both Count* and Split* functions in both bytes and strings packages. |
In my benchmark results, the performance of your modified genSplit version does not improve as much as simply separating the code (as I post). Is there explaination for that? |
#go1.7, linux, amd64
The genSplit function used by Split, SplitAfter and SplitAfterN is simplified in the IF statement of sep length, maybe for code expression. However it results in extra conditional executions in either case of len(sep)==1 or len(sep)>1
if s[i] == c && (len(sep) == 1 || s[i:i+len(sep)] == sep) {
...
}
Just seperating that into two parts according to sep length gains ~15% improvement in performace (15% time reduction) in either case of len(sep)==1 or len(sep)>1.
func genSplit(s, sep string, sepSave, n int) []string {
}
The text was updated successfully, but these errors were encountered: