aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-01-03 15:54:56 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-01-03 15:22:24 +0000
commit8a70020f31559cb43209df6788c90da90f05cec2 (patch)
tree5341c2c4ccf97f1a8dfee4672f110596d0024715 /prog
parentfb427a0782000106c62de76d251e5a02de5406a9 (diff)
prog: optimize foreachArgImpl()
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)
Diffstat (limited to 'prog')
-rw-r--r--prog/analysis.go12
1 files 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 {