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: map lookup with result of inlined method cannot use fast path #44898
Comments
cc @josharian |
/cc @randall77 |
I think this is because it literally needs
Since this optimization is done in walk, it's hard to determine (1) that the index used is a byte slice converted to a string, and (2) that the byte slice was not modified between the string conversion and the map indexing. (2) is particularly hard at this phase of the compiler. So while I think this may be fixable, it will certainly take a lot of work. Either plumbing new information into walk, or moving this optimization to SSA where that info is easier to glean. Not sure it's worth all that work. |
@randall77 Thanks for investigating this. What state do you think this issue should be moved to next? |
FWIW this was quite surprising for me when I came across the issue (the actual code in question was returning the string value of a field in a by-value struct, defined that way to prevent unintentional conversions between to My assumption that the inlined function would be exactly equivalent to the expression inline led to a significant performance regression. ISTM that doing the optimisation at SSA level would be nicer (and potentially open the door to other optimisations, such as passing |
Not entirely related, but a careful implementation of #29095 can help here too. |
Given the above type definition, I would expect a map lookup of
x.S()
to compile to the same code as a map lookup ofstring(x)
, but it does not.That is, the following
lookup1
function is slower thanlookup2
, which it should not be:Here's the code in a benchmark: https://play.golang.org/p/uw-AHzeos-v
Here are the benchmark results:
The text was updated successfully, but these errors were encountered: