From a7a1cea58a31ffafc3d6473559349a52d46c33a0 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 3 Jul 2024 17:36:57 +0200 Subject: pkg/corpus: don't keep serialized programs in memory We only need serialized representation on some rare operations (some web UI pages, and first hub connect). Don't keep them in memory. In my instance this saves 503MB (15.5%) of heap, which reduces RSS by 1GB (2x due to GC). --- pkg/corpus/corpus.go | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'pkg/corpus') diff --git a/pkg/corpus/corpus.go b/pkg/corpus/corpus.go index 5b2b9983f..4ad4f6f27 100644 --- a/pkg/corpus/corpus.go +++ b/pkg/corpus/corpus.go @@ -60,14 +60,13 @@ type ItemUpdate struct { // too hard to synchonize accesses to them across the whole project. // When Corpus updates one of its items, it saves a copy of it. type Item struct { - Sig string - Call int - Prog *prog.Prog - ProgData []byte // to save some Serialize() calls - HasAny bool // whether the prog contains squashed arguments - Signal signal.Signal - Cover []uint64 - Updates []ItemUpdate + Sig string + Call int + Prog *prog.Prog + HasAny bool // whether the prog contains squashed arguments + Signal signal.Signal + Cover []uint64 + Updates []ItemUpdate } func (item Item) StringCall() string { @@ -109,14 +108,13 @@ func (corpus *Corpus) Save(inp NewInput) { newCover.Merge(old.Cover) newCover.Merge(inp.Cover) newItem := &Item{ - Sig: sig, - Prog: old.Prog, - ProgData: progData, - Call: old.Call, - HasAny: old.HasAny, - Signal: newSignal, - Cover: newCover.Serialize(), - Updates: append([]ItemUpdate{}, old.Updates...), + Sig: sig, + Prog: old.Prog, + Call: old.Call, + HasAny: old.HasAny, + Signal: newSignal, + Cover: newCover.Serialize(), + Updates: append([]ItemUpdate{}, old.Updates...), } const maxUpdates = 32 if len(newItem.Updates) < maxUpdates { @@ -125,14 +123,13 @@ func (corpus *Corpus) Save(inp NewInput) { corpus.progs[sig] = newItem } else { corpus.progs[sig] = &Item{ - Sig: sig, - Call: inp.Call, - Prog: inp.Prog, - ProgData: progData, - HasAny: inp.Prog.ContainsAny(), - Signal: inp.Signal, - Cover: inp.Cover, - Updates: []ItemUpdate{update}, + Sig: sig, + Call: inp.Call, + Prog: inp.Prog, + HasAny: inp.Prog.ContainsAny(), + Signal: inp.Signal, + Cover: inp.Cover, + Updates: []ItemUpdate{update}, } corpus.saveProgram(inp.Prog, inp.Signal) } -- cgit mrf-deployment