[dev.fuzz] internal/fuzz: use scratch []byte for mutations

The mutator will now use a scratch []byte when mutating
[]byte and string types.

I ran the following target locally:

    func FuzzBytesFromStringCmp(f *testing.F) {
        f.Fuzz(func(t *testing.T, a, b string) {
            bytes.Compare([]byte(a), []byte(b))
        })
    }

Before the change, execs were <400/sec:

    === FUZZ  FuzzBytesFromStringCmp
    fuzzing, elapsed: 3.0s, execs: 1090 (363/sec), workers: 8 ...
    fuzzing, elapsed: 6.0s, execs: 2290 (382/sec), workers: 8 ...
    fuzzing, elapsed: 9.0s, execs: 3491 (388/sec), workers: 8 ...
    fuzzing, elapsed: 12.0s, execs: 4691 (391/sec), workers: 8 ...
    fuzzing, elapsed: 15.0s, execs: 5869 (391/sec), workers: 8 ...
    fuzzing, elapsed: 18.0s, execs: 7056 (392/sec), workers: 8 ...

After the change, the execs are ~6000/sec

    === FUZZ  FuzzBytesFromStringCmp
    fuzzing, elapsed: 3.0s, execs: 155129 (51687/sec), workers: 8 ...
    fuzzing, elapsed: 6.0s, execs: 303710 (50606/sec), workers: 8 ...
    fuzzing, elapsed: 9.0s, execs: 454314 (50470/sec), workers: 8 ...
    fuzzing, elapsed: 12.0s, execs: 603212 (50262/sec), workers: 8 ...
    fuzzing, elapsed: 15.0s, execs: 756165 (50401/sec), workers: 8 ...
    fuzzing, elapsed: 18.0s, execs: 899293 (49955/sec), workers: 8 ...

Which is comparable to the same target with two []byte as input:

    === FUZZ  FuzzBytesCmp
    fuzzing, elapsed: 3.0s, execs: 152348 (50757/sec), workers: 8 ...
    fuzzing, elapsed: 6.0s, execs: 314386 (52387/sec), workers: 8 ...
    fuzzing, elapsed: 9.0s, execs: 487413 (54148/sec), workers: 8 ...
    fuzzing, elapsed: 12.0s, execs: 646886 (53901/sec), workers: 8 ...
    fuzzing, elapsed: 15.0s, execs: 814257 (54266/sec), workers: 8 ...
    fuzzing, elapsed: 18.0s, execs: 983214 (54619/sec), workers: 8 ...

Benchark results:
name                      old time/op    new time/op    delta
MutatorBytes/1-8          7.70ms ± 3%    0.00ms ± 3%   -99.99%  (p=0.029 n=4+4)
MutatorBytes/10-8         7.88ms ± 2%    0.00ms ± 6%   -99.99%  (p=0.029 n=4+4)
MutatorBytes/100-8        7.87ms ± 1%    0.00ms ± 2%   -99.99%  (p=0.029 n=4+4)
MutatorBytes/1000-8       8.11ms ± 5%    0.00ms ± 2%   -99.99%  (p=0.029 n=4+4)
MutatorBytes/10000-8      8.11ms ± 4%    0.00ms ± 2%   -99.99%  (p=0.029 n=4+4)
MutatorBytes/100000-8     8.28ms ±10%    0.00ms ± 4%   -99.96%  (p=0.029 n=4+4)
MutatorString/1-8         7.89ms ± 5%    0.00ms ±17%   -99.99%  (p=0.029 n=4+4)
MutatorString/10-8        7.91ms ± 4%    0.00ms ± 7%   -99.99%  (p=0.029 n=4+4)
MutatorString/100-8       8.08ms ± 4%    0.00ms ± 7%   -99.99%  (p=0.029 n=4+4)
MutatorString/1000-8      8.11ms ± 6%    0.00ms ±11%   -99.99%  (p=0.029 n=4+4)
MutatorString/10000-8     8.04ms ± 7%    0.00ms ± 8%   -99.98%  (p=0.029 n=4+4)
MutatorString/100000-8    8.24ms ± 7%    0.01ms ±13%   -99.82%  (p=0.029 n=4+4)

Fixes #46543

Change-Id: I8b078ed3adc1bb6310c33afc49bb6cd78e7e976c
Reviewed-on: https://go-review.googlesource.com/c/go/+/324849
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
3 files changed
tree: 6e2b4dcf463ce1e79e093fb8f29297c8240f24c8
  1. .github/
  2. api/
  3. doc/
  4. lib/
  5. misc/
  6. src/
  7. test/
  8. .gitattributes
  9. .gitignore
  10. AUTHORS
  11. codereview.cfg
  12. CONTRIBUTING.md
  13. CONTRIBUTORS
  14. LICENSE
  15. PATENTS
  16. README.md
  17. SECURITY.md
README.md

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://golang.org/dl/.

After downloading a binary release, visit https://golang.org/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://golang.org/doc/contribute.html.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.