From a7e4a49fae26bf52b4b8f26aeebc50d947dc1abc Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 20 Jan 2017 23:55:25 +0100 Subject: all: spot optimizations A bunch of spot optmizations after cpu/memory profiling: 1. Optimize hot-path coverage comparison in fuzzer. 2. Don't allocate and copy serialized program, serialize directly into shmem. 3. Reduce allocations during parsing of output shmem (encoding/binary sucks). 4. Don't allocate and copy coverage arrays, refer directly to the shmem region (we are not going to mutate them). 5. Don't validate programs outside of tests, validation allocates tons of memory. 6. Replace the choose primitive with simpler switches. Choose allocates fullload of memory (for int, func, and everything the func refers). 7. Other minor optimizations. --- prog/encodingexec_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'prog/encodingexec_test.go') diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go index f2476351c..b7a6b9463 100644 --- a/prog/encodingexec_test.go +++ b/prog/encodingexec_test.go @@ -14,9 +14,12 @@ import ( func TestSerializeForExecRandom(t *testing.T) { rs, iters := initTest(t) + buf := make([]byte, ExecBufferSize) for i := 0; i < iters; i++ { p := Generate(rs, 10, nil) - p.SerializeForExec(i % 16) + if err := p.SerializeForExec(buf, i%16); err != nil { + t.Fatalf("failed to serialize: %v", err) + } } } @@ -249,15 +252,22 @@ func TestSerializeForExec(t *testing.T) { }, } + buf := make([]byte, ExecBufferSize) for i, test := range tests { p, err := Deserialize([]byte(test.prog)) if err != nil { t.Fatalf("failed to deserialize prog %v: %v", i, err) } t.Run(fmt.Sprintf("%v:%v", i, p.String()), func(t *testing.T) { - data := p.SerializeForExec(i % 16) + if err := p.SerializeForExec(buf, i%16); err != nil { + t.Fatalf("failed to serialize: %v", err) + } w := new(bytes.Buffer) binary.Write(w, binary.LittleEndian, test.serialized) + data := buf + if len(data) > len(w.Bytes()) { + data = data[:len(w.Bytes())] + } if !bytes.Equal(data, w.Bytes()) { got := make([]uint64, len(data)/8) binary.Read(bytes.NewReader(data), binary.LittleEndian, &got) -- cgit mrf-deployment