Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: optimizing multiple accesses to same key in map #17133
I was reviewing some code for performance issues, and the profile pointed me to a function that was accessing the same map element multiple times like this:
data[key].Foo = 1 data[key].Bar.Baz += 4 [...]
The profile showed many calls to
Yes, this would be awesome. I've been pondering it. I think we just want to recognize redundant calls and use the same return value from mapaccess* (the pointer to the value) again.
We probably need a mapaccess variant, "lookup key, plus allocate key->0 if not found" method.
Also good for
referenced this issue
Feb 12, 2017
This is what mapassign already does. I believe there's nothing blocking us from compiling
As for recognizing repeated map lookups, could that be handled by CSE if we mapped OMAPINDEX to a high-level SSA Op and later lowered it into a runtime call?