go/src
Daniel Martí c4078a1998 text/tabwriter: use a single defer per Write call
Lines with single cells prompt a flush. Unfortunately, a call to
Writer.Flush also means two defers, which is an expensive operation to
do if many lines consist of single cells.

This is common when formatting code with aligned comments. Most lines
aren't going to have any comments at all, so the performance hit is
going to be noticeable.

The Write method already has a "defer handlePanic" of its own, so we
don't need to worry about panics leaking out. The error will now mention
"Write" instead of "Flush" if a panic is encountered during that nested
flush, but arguably that's a good thing; the user called Write, not
Flush.

For the reset call, add a non-deferred call as part of flushNoDefers, as
that's still necessary. Otherwise, the exported Flush method still does
a "defer b.reset".

The current tabwriter benchmarks are unaffected, since they don't
contain many single-cell lines, and because lines are written one at a
time. For that reason, we add a benchmark which has both of these
characteristics.

name    old time/op    new time/op    delta
Code-8    2.72µs ± 0%    1.77µs ± 0%  -34.88%  (p=0.000 n=6+5)

name    old alloc/op   new alloc/op   delta
Code-8      648B ± 0%      648B ± 0%     ~     (all equal)

name    old allocs/op  new allocs/op  delta
Code-8      13.0 ± 0%      13.0 ± 0%     ~     (all equal)

Perhaps unsurprisingly, go/printer also gets a bit faster, as it too
buffers its output before writing it to tabwriter.

name     old time/op  new time/op  delta
Print-8  6.53ms ± 0%  6.39ms ± 0%  -2.22%  (p=0.008 n=5+5)

Change-Id: Ie01fea5ced43886a9eb796cb1e6c810f7a810853
Reviewed-on: https://go-review.googlesource.com/c/go/+/166797
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-03-12 22:34:30 +00:00
..
archive archive/tar, syscall: add statUnix for aix/ppc64 2019-02-27 23:40:20 +00:00
bufio bufio: fix emptyFinalToken example to handle multiple Reads 2019-03-02 18:28:10 +00:00
builtin
bytes bytes, strings: speed up TrimSpace 4-5x for common ASCII cases 2019-03-12 15:52:17 +00:00
cmd cmd/go: fix typo in GoGetInsecure to actually set GOPROXY 2019-03-12 21:08:33 +00:00
compress compress/gzip: clarify that Multistream gzip requires a ByteReader 2019-02-26 23:02:40 +00:00
container container/heap: avoid memory leak in example 2019-02-26 23:42:26 +00:00
context
crypto all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor' 2019-03-11 20:28:54 +00:00
database/sql database/sql: fix comment grammar 2019-03-07 05:19:01 +00:00
debug debug/gosym: simplify parsing symbol name rule 2019-03-09 00:24:42 +00:00
encoding all: simplify multiple for loops 2019-03-08 14:29:19 +00:00
errors errors: add Unwrap, Is, and As 2019-02-27 19:09:40 +00:00
expvar
flag flag: improve docs for PrintDefaults; clarify how to change output destination 2019-01-21 05:30:12 +00:00
fmt fmt: rewrite if-else-if-else chain to switch statement 2019-03-06 15:12:49 +00:00
go go/build: bypass importGo if srcDir is in GOROOT/src 2019-03-12 05:00:20 +00:00
hash hash/fnv: use bits.Mul64 for 128-bit hash 2018-12-10 22:50:48 +00:00
html html/template: prevent test from failing with nil pointer dereference 2019-03-02 01:53:40 +00:00
image image/png: delete unused statement 2019-02-28 18:24:51 +00:00
index/suffixarray
internal internal/bytealg: share code for equal functions on arm 2019-03-12 07:27:56 +00:00
io io: align style of test comments in multi_test.go 2019-02-26 23:01:20 +00:00
log log: make the name of error clearer 2019-03-07 15:36:29 +00:00
math math/big: implement Int.TrailingZeroBits 2019-03-12 13:18:27 +00:00
mime mime/multipart: quote boundary in Content-Type if necessary 2018-12-13 23:58:06 +00:00
net net/http: add missing error checks in tests 2019-03-11 21:40:21 +00:00
os os: drop special case for FreeBSD 10.4 in newFile 2019-03-12 06:33:01 +00:00
path path/filepath: don't discard .. in EvalSymlinks 2019-03-05 01:01:11 +00:00
plugin plugin: fix build constraint to disable test on linux/arm64 2018-11-28 18:14:20 +00:00
reflect reflect: make all flag.mustBe* methods inlinable 2019-03-09 19:50:24 +00:00
regexp regexp: add ReplaceAllStringFunc example 2019-02-27 21:48:41 +00:00
runtime runtime: safely load DLLs 2019-03-10 05:40:13 +00:00
sort sort: change let to let's 2019-01-27 01:34:56 +00:00
strconv strconv: simplify (*extFloat).Multiply using math/bits.Mul64 2019-03-04 22:25:21 +00:00
strings bytes, strings: speed up TrimSpace 4-5x for common ASCII cases 2019-03-12 15:52:17 +00:00
sync sync: allow inlining the RWMutex.RUnlock fast path 2019-03-09 16:34:17 +00:00
syscall syscall: correctly set up uid/gid mappings in user namespaces 2019-03-12 00:40:34 +00:00
testdata
testing testing: enable examples on js/wasm with non os.Pipe runExample 2019-03-11 18:59:53 +00:00
text text/tabwriter: use a single defer per Write call 2019-03-12 22:34:30 +00:00
time time: add support for day-of-year in Format and Parse 2019-03-08 01:21:33 +00:00
unicode unicode: improve generated comments for categories 2018-11-28 03:12:48 +00:00
unsafe cmd/compile: assume unsafe pointer arithmetic generates non-nil results 2018-11-14 21:01:36 +00:00
vendor all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor' 2019-03-11 20:28:54 +00:00
Make.dist
all.bash
all.bat
all.rc
bootstrap.bash
buildall.bash
clean.bash
clean.bat
clean.rc
cmp.bash
go.mod all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor' 2019-03-11 20:28:54 +00:00
go.sum all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor' 2019-03-11 20:28:54 +00:00
iostest.bash cmd/dist: build exec wrappers during bootstrap 2019-02-26 17:59:23 +00:00
make.bash cmd,std: add go.mod files 2019-03-11 20:27:41 +00:00
make.bat cmd,std: add go.mod files 2019-03-11 20:27:41 +00:00
make.rc cmd,std: add go.mod files 2019-03-11 20:27:41 +00:00
naclmake.bash
nacltest.bash
race.bash cmd,runtime: enable race detector on arm64 2018-11-13 16:57:22 +00:00
race.bat
run.bash all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor' 2019-03-11 20:28:54 +00:00
run.bat build: clear GO111MODULE during make.bash etc 2018-11-16 18:54:22 +00:00
run.rc build: clear GO111MODULE during make.bash etc 2018-11-16 18:54:22 +00:00