Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
strings,bytes: tune inliner for Contains or add ContainsByte #32257
For strings.Index there already exists a specialized version strings.IndexByte besides strings.IndexRune.
Sampling from a large go code corpus:
There is overhead for both the binary code size, loading the string from memory and generally performance loss when using Contains or ContainsRune instead of ContainsByte (that uses IndexByte).
Make the inliner sufficiently aware of Contains and ContainsRune (+possible code layout change) to inline IndexByte calls directly.
Add a specialized ContainsByte function to strings and bytes package.
Downside: current code does not immediately get the benefits without change.
Benchmark (I have seen 2 clock cycle variances due to branch addresses depending on where benchmark loops are, these here favor Contains on my Workstation)