From 8a70020f31559cb43209df6788c90da90f05cec2 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 3 Jan 2024 15:54:56 +0100 Subject: prog: optimize foreachArgImpl() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per profiling, (*GroupArg).Size() calls from this function were one of the hottest paths during the BenchmarkMutate() benchmark. Some of those calls are made only to issue a runtime panic, which we arguably don't need unless we're testing the code. After the changes: │ /tmp/original │ /tmp/new │ │ sec/op │ sec/op vs base │ Mutate-36 221.8µ ± 4% 179.0µ ± 3% -19.31% (p=0.000 n=15) --- prog/analysis.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/prog/analysis.go b/prog/analysis.go index 850fdb1dd..47c470926 100644 --- a/prog/analysis.go +++ b/prog/analysis.go @@ -155,11 +155,13 @@ func foreachArgImpl(arg Arg, ctx *ArgCtx, f func(Arg, *ArgCtx)) { totalSize = ctx.Offset - ctx0.Offset } } - claimedSize := a.Size() - varlen := a.Type().Varlen() - if varlen && totalSize > claimedSize || !varlen && totalSize != claimedSize { - panic(fmt.Sprintf("bad group arg size %v, should be <= %v for %#v type %#v", - totalSize, claimedSize, a, a.Type().Name())) + if debug { + claimedSize := a.Size() + varlen := a.Type().Varlen() + if varlen && totalSize > claimedSize || !varlen && totalSize != claimedSize { + panic(fmt.Sprintf("bad group arg size %v, should be <= %v for %#v type %#v", + totalSize, claimedSize, a, a.Type().Name())) + } } case *PointerArg: if a.Res != nil { -- cgit mrf-deployment