From fd4c685094c967d70eb9b535f392463f3b8ec16d Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Sun, 28 Nov 2021 06:20:34 +0900 Subject: [PATCH] msgpack: add bounds check hint to compiler to fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta _correctFilels/Named-20 9.55µs ± 0% 9.45µs ± 1% -1.02% (p=0.008 n=5+5) _correctFilels/Empty-20 9.60µs ± 0% 9.88µs ±10% ~ (p=1.000 n=5+5) _correctFilels/OmitEmpty-20 10.9µs ± 1% 11.2µs ± 6% ~ (p=0.095 n=5+5) [Geo mean] 10.0µs 10.1µs +1.38% name old alloc/op new alloc/op delta _correctFilels/Named-20 4.75kB ± 0% 4.75kB ± 0% ~ (all equal) _correctFilels/Empty-20 4.75kB ± 0% 4.75kB ± 0% ~ (p=0.333 n=5+4) _correctFilels/OmitEmpty-20 5.10kB ± 0% 5.10kB ± 0% ~ (all equal) [Geo mean] 4.86kB 4.86kB -0.00% name old allocs/op new allocs/op delta _correctFilels/Named-20 96.0 ± 0% 96.0 ± 0% ~ (all equal) _correctFilels/Empty-20 96.0 ± 0% 96.0 ± 0% ~ (all equal) _correctFilels/OmitEmpty-20 96.0 ± 0% 96.0 ± 0% ~ (all equal) [Geo mean] 96.0 96.0 +0.00% Signed-off-by: Koichi Shiraishi --- msgpack/field.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msgpack/field.go b/msgpack/field.go index de7abc7f..69c3bbb0 100644 --- a/msgpack/field.go +++ b/msgpack/field.go @@ -74,6 +74,8 @@ func collectFields(fields []*field, t reflect.Type, visited map[reflect.Type]boo } if len(index) == d { + _ = fields[len(fields)-1] // bounds check hint to compiler + // There is another field with same name and same depth // Remove that field and skip this field j := 0