cmd/compile: re-use the already calculated map key hash on multiple accesses/assignments of map items for the given key #70594
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
The problem
The following code is quite common:
The problem with this code is that the hash for the
key
is calculated two times here:s.m
at the step 1.s.m
at the step 2.The step 1 and step 2 are both executed in the common case when the
key
is missing ins
. This means that CPU time is wasted at the step 2 on repeated calculation of the hash for thekey
.The solution
It would be great from performance PoV if Go compiler could re-use the already calculated hash for the
key
at the step 2 above. The performance improvement increases with the size of thekey
.Additional details
There is another frequently used pattern, which could benefit from this optimization:
Another common variation of the previous function:
It would be great from the performance PoV if the hash for the
key
is calculated only once inside these functions.The text was updated successfully, but these errors were encountered: