From 4b76dd258977f4bc9b8a1996680f8b9fd96713d2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 25 Apr 2020 15:05:19 +0200 Subject: prog: use Ref as Arg type Use Ref in Arg instead of full Type interface. This reduces size of all args. In partiuclar the most common ConstArg is reduces from 32 bytes to 16 and now does not contain any pointers (better for GC). Running syz-db bench on a beefy corpus: before: allocs 7262 MB (18 M), next GC 958 MB, sys heap 1279 MB, live allocs 479 MB (8 M), time 9.704699958s allocs 7262 MB (18 M), next GC 958 MB, sys heap 1279 MB, live allocs 479 MB (8 M), time 9.873792394s allocs 7262 MB (18 M), next GC 958 MB, sys heap 1279 MB, live allocs 479 MB (8 M), time 9.820479906s after: allocs 7163 MB (18 M), next GC 759 MB, sys heap 1023 MB, live allocs 379 MB (8 M), time 8.938939937s allocs 7163 MB (18 M), next GC 759 MB, sys heap 1087 MB, live allocs 379 MB (8 M), time 9.410243167s allocs 7163 MB (18 M), next GC 759 MB, sys heap 1023 MB, live allocs 379 MB (8 M), time 9.38225806s Max heap and live heap are reduced by 20%. Update #1580 --- prog/any.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'prog/any.go') diff --git a/prog/any.go b/prog/any.go index 7bf38b6be..bb80eaa38 100644 --- a/prog/any.go +++ b/prog/any.go @@ -135,8 +135,9 @@ func (target *Target) squashPtr(arg *PointerArg) { size0 := res0.Size() var elems []Arg target.squashPtrImpl(arg.Res, &elems) - arg.typ = target.getAnyPtrType(arg.Type().Size()) - arg.Res = MakeGroupArg(arg.typ.(*PtrType).Elem, DirIn, elems) + newType := target.getAnyPtrType(arg.Type().Size()) + arg.ref = newType.ref() + arg.Res = MakeGroupArg(newType.Elem, DirIn, elems) if size := arg.Res.Size(); size != size0 { panic(fmt.Sprintf("squash changed size %v->%v for %v", size0, size, res0.Type())) } @@ -206,28 +207,30 @@ func (target *Target) squashConst(arg *ConstArg, elems *[]Arg) { } func (target *Target) squashResult(arg *ResultArg, elems *[]Arg) { + var typ *ResourceType index := -1 switch arg.Type().Format() { case FormatNative, FormatBigEndian: switch arg.Size() { case 2: - arg.typ, index = target.any.res16, 1 + typ, index = target.any.res16, 1 case 4: - arg.typ, index = target.any.res32, 2 + typ, index = target.any.res32, 2 case 8: - arg.typ, index = target.any.res64, 3 + typ, index = target.any.res64, 3 default: panic("bad size") } case FormatStrDec: - arg.typ, index = target.any.resdec, 4 + typ, index = target.any.resdec, 4 case FormatStrHex: - arg.typ, index = target.any.reshex, 5 + typ, index = target.any.reshex, 5 case FormatStrOct: - arg.typ, index = target.any.resoct, 6 + typ, index = target.any.resoct, 6 default: panic("bad") } + arg.ref = typ.ref() arg.dir = DirIn *elems = append(*elems, MakeUnionArg(target.any.union, DirIn, arg, index)) } -- cgit mrf-deployment