Optimize blueprint.variationMap.equal

blueprint.variationMap.Equal was responsible for 11.5% of allocations
and 2.2% of allocated memory.  reflect.DeepEquals is an expensive way
to compare a map.  variationMap.subsetOf is already iterating through
the elements of the map to compare them, replace equal with a check that
the maps are the same length and then reuse subsetOf to check that the
have the same keys and values.

Test: SOONG_PROFILE_MEM=/tmp/mem.pprof m nothing
Change-Id: Ifb7cdf612e5455fd2f412488b7f94416c4e70c54
This commit is contained in:
Colin Cross 2024-02-01 14:31:47 -08:00
parent 2ef2c35664
commit 1d82de2aab

View file

@ -441,7 +441,10 @@ func (vm variationMap) subsetOf(other variationMap) bool {
} }
func (vm variationMap) equal(other variationMap) bool { func (vm variationMap) equal(other variationMap) bool {
return reflect.DeepEqual(vm, other) if len(vm) != len(other) {
return false
}
return vm.subsetOf(other)
} }
type singletonInfo struct { type singletonInfo struct {