From 1d82de2aabc986ad1fc85315167baa0f3343f8a7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 1 Feb 2024 14:31:47 -0800 Subject: [PATCH] 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 --- context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index a53d421..21a28c9 100644 --- a/context.go +++ b/context.go @@ -441,7 +441,10 @@ func (vm variationMap) subsetOf(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 {