]> Cypherpunks repositories - gostls13.git/commit
[dev.fuzz] internal/fuzz: reduce allocation in the mutator
authorJay Conrod <jayconrod@google.com>
Thu, 1 Apr 2021 21:51:18 +0000 (17:51 -0400)
committerJay Conrod <jayconrod@google.com>
Mon, 5 Apr 2021 17:04:08 +0000 (17:04 +0000)
commitb975d0baa0e0d4a733c4f5ff86ed81514deb53b2
tree95ae821ca4133b1809969f83fc54fda24da9fef4
parent9d4d5ee66dc53f6640dd8f5333df69db4df3b044
[dev.fuzz] internal/fuzz: reduce allocation in the mutator

When mutating a byte slice, mutate in place, and only allocate once if
the slice's capacity is less than the maximum size.

mutateBytes already should not allocate; we check a post-condition
that the slice's data pointer does not change.

This speeds up the mutator from 4 ms per value to 200-600 ns. For
example:

    goos: darwin
    goarch: amd64
    pkg: internal/fuzz
    cpu: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    BenchmarkMutatorBytes/1-8                5908735               275.3 ns/op
    BenchmarkMutatorBytes/10-8               5198473               282.0 ns/op
    BenchmarkMutatorBytes/100-8              4304750               233.9 ns/op
    BenchmarkMutatorBytes/1000-8             4623988               295.2 ns/op
    BenchmarkMutatorBytes/10000-8            4252104               458.5 ns/op
    BenchmarkMutatorBytes/100000-8           1236751               950.8 ns/op
    PASS
    ok      internal/fuzz   12.993s

Change-Id: I4bf2a04be6c648ef440af2c62bf0ffa3d310172c
Reviewed-on: https://go-review.googlesource.com/c/go/+/306675
Trust: Jay Conrod <jayconrod@google.com>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Katie Hockman <katie@golang.org>
src/internal/fuzz/fuzz.go
src/internal/fuzz/mutator.go
src/internal/fuzz/mutator_test.go [new file with mode: 0644]
src/internal/fuzz/worker.go