1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:04:45 -07:00
go/test
Russ Cox 8552047a32 cmd/internal/gc: optimize append + write barrier
The code generated for x = append(x, v) is roughly:

	t := x
	if len(t)+1 > cap(t) {
		t = grow(t)
	}
	t[len(t)] = v
	len(t)++
	x = t

We used to generate this code as Go pseudocode during walk.
Generate it instead as actual instructions during gen.

Doing so lets us apply a few optimizations. The most important
is that when, as in the above example, the source slice and the
destination slice are the same, the code can instead do:

	t := x
	if len(t)+1 > cap(t) {
		t = grow(t)
		x = {base(t), len(t)+1, cap(t)}
	} else {
		len(x)++
	}
	t[len(t)] = v

That is, in the fast path that does not reallocate the array,
only the updated length needs to be written back to x,
not the array pointer and not the capacity. This is more like
what you'd write by hand in C. It's faster in general, since
the fast path elides two of the three stores, but it's especially
faster when the form of x is such that the base pointer write
would turn into a write barrier. No write, no barrier.

name                   old mean              new mean              delta
BinaryTree17            5.68s × (0.97,1.04)   5.81s × (0.98,1.03)   +2.35% (p=0.023)
Fannkuch11              4.41s × (0.98,1.03)   4.35s × (1.00,1.00)     ~    (p=0.090)
FmtFprintfEmpty        92.7ns × (0.91,1.16)  86.0ns × (0.94,1.11)   -7.31% (p=0.038)
FmtFprintfString        281ns × (0.96,1.08)   276ns × (0.98,1.04)     ~    (p=0.219)
FmtFprintfInt           288ns × (0.97,1.06)   274ns × (0.98,1.06)   -4.94% (p=0.002)
FmtFprintfIntInt        493ns × (0.97,1.04)   506ns × (0.99,1.01)   +2.65% (p=0.009)
FmtFprintfPrefixedInt   423ns × (0.97,1.04)   391ns × (0.99,1.01)   -7.52% (p=0.000)
FmtFprintfFloat         598ns × (0.99,1.01)   566ns × (0.99,1.01)   -5.27% (p=0.000)
FmtManyArgs            1.89µs × (0.98,1.05)  1.91µs × (0.99,1.01)     ~    (p=0.231)
GobDecode              14.8ms × (0.98,1.03)  15.3ms × (0.99,1.02)   +3.01% (p=0.000)
GobEncode              12.3ms × (0.98,1.01)  11.5ms × (0.97,1.03)   -5.93% (p=0.000)
Gzip                    656ms × (0.99,1.05)   645ms × (0.99,1.01)     ~    (p=0.055)
Gunzip                  142ms × (1.00,1.00)   142ms × (1.00,1.00)   -0.32% (p=0.034)
HTTPClientServer       91.2µs × (0.97,1.04)  90.5µs × (0.97,1.04)     ~    (p=0.468)
JSONEncode             32.6ms × (0.97,1.08)  32.0ms × (0.98,1.03)     ~    (p=0.190)
JSONDecode              114ms × (0.97,1.05)   114ms × (0.99,1.01)     ~    (p=0.887)
Mandelbrot200          6.11ms × (0.98,1.04)  6.04ms × (1.00,1.01)     ~    (p=0.167)
GoParse                6.66ms × (0.97,1.04)  6.47ms × (0.97,1.05)   -2.81% (p=0.014)
RegexpMatchEasy0_32     159ns × (0.99,1.00)   171ns × (0.93,1.07)   +7.19% (p=0.002)
RegexpMatchEasy0_1K     538ns × (1.00,1.01)   550ns × (0.98,1.01)   +2.30% (p=0.000)
RegexpMatchEasy1_32     138ns × (1.00,1.00)   135ns × (0.99,1.02)   -1.60% (p=0.000)
RegexpMatchEasy1_1K     869ns × (0.99,1.01)   879ns × (1.00,1.01)   +1.08% (p=0.000)
RegexpMatchMedium_32    252ns × (0.99,1.01)   243ns × (1.00,1.00)   -3.71% (p=0.000)
RegexpMatchMedium_1K   72.7µs × (1.00,1.00)  70.3µs × (1.00,1.00)   -3.34% (p=0.000)
RegexpMatchHard_32     3.85µs × (1.00,1.00)  3.82µs × (1.00,1.01)   -0.81% (p=0.000)
RegexpMatchHard_1K      118µs × (1.00,1.00)   117µs × (1.00,1.00)   -0.56% (p=0.000)
Revcomp                 920ms × (0.97,1.07)   917ms × (0.97,1.04)     ~    (p=0.808)
Template                129ms × (0.98,1.03)   114ms × (0.99,1.01)  -12.06% (p=0.000)
TimeParse               619ns × (0.99,1.01)   622ns × (0.99,1.01)     ~    (p=0.062)
TimeFormat              661ns × (0.98,1.04)   665ns × (0.99,1.01)     ~    (p=0.524)

See next CL for combination with a similar optimization for slice.
The benchmarks that are slower in this CL are still faster overall
with the combination of the two.

Change-Id: I2a7421658091b2488c64741b4db15ab6c3b4cb7e
Reviewed-on: https://go-review.googlesource.com/9812
Reviewed-by: David Chase <drchase@google.com>
2015-05-12 17:55:09 +00:00
..
bench build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
bugs test: migrate remaining tests to run.go 2014-12-22 22:41:34 +00:00
chan cmd/gc: implement 'for range x {' 2014-07-16 19:27:10 -04:00
ddd2.dir
dwarf
fixedbugs cmd/internal/gc: detect bad append(f()) during type check 2015-05-12 16:26:35 +00:00
import2.dir
import4.dir test: match gccgo import error messages 2013-12-12 19:02:11 -08:00
interface cmd/internal/gc: improve "type *X has no field or method M" message 2015-05-07 16:21:57 +00:00
ken
method4.dir cmd/gc: do not omit wrapper for expression (interface{...}).F 2014-01-07 13:26:48 +01:00
safe
stress build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
syntax test: match gccgo error messages 2013-12-12 17:18:12 -08:00
64bit.go
235.go
alias1.go
alias.go
append.go
args.go
assign1.go
assign.go cmd/gc: prohibit short variable declarations containing duplicate symbols 2014-10-06 17:16:39 -04:00
bigalg.go
bigmap.go
blank1.go test: match gccgo error messages for blank1.go 2013-09-28 15:19:05 -07:00
blank.go test: revert changes made for Go SSA interpreter test. 2013-10-08 14:36:20 -04:00
bom.go
bombad.go
bounds.go
chancap.go
chanlinear.go runtime: test for linear enqueue/dequeue behavior 2014-12-08 22:18:17 +00:00
char_lit1.go
char_lit.go
clearfat.go [dev.power64] 9g: fix under-zeroing in clearfat 2014-10-31 11:08:27 -04:00
closedchan.go
closure1.go cmd/gc: capture variables by value 2015-01-29 13:07:30 +00:00
closure2.go cmd/gc: fix capturing by value for range statements 2015-02-03 15:48:48 +00:00
closure.go
cmp6.go cmd/gc: do not consider length zero arrays as comparable. 2014-01-31 00:30:56 +01:00
cmp.go cmd/gc: do not nop-convert equivalent but different interface types. 2014-02-27 08:07:50 +01:00
cmplx.go
cmplxdivide1.go
cmplxdivide.c test: comment the behavior and use of cmplxdivide* 2015-01-15 00:00:06 +00:00
cmplxdivide.go test: comment the behavior and use of cmplxdivide* 2015-01-15 00:00:06 +00:00
complit1.go
complit.go
compos.go
const1.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
const2.go
const3.go
const4.go
const5.go cmd/gc: reject builtin function calls in len(fixed array) constants 2014-04-03 19:04:33 -04:00
const6.go test: match gccgo error strings. 2013-06-26 18:05:02 +02:00
const.go
convert1.go
convert3.go
convert.go
convlit1.go
convlit.go cmd/internal/gc: unsafe.Pointer constants may only be converted to uintptr 2015-05-07 23:54:28 +00:00
convT2X.go
copy.go
crlf.go
ddd1.go
ddd2.go
ddd.go
decl.go
declbad.go
defer.go
deferfin.go runtime: combine small NoScan allocations 2014-01-24 22:35:11 +04:00
deferprint.go
deferprint.out
divide.go
divmod.go all: fix a few spelling errors in source comments 2013-12-27 08:59:02 -08:00
empty.go
env.go
eof1.go
eof.go
errchk test/errchk: use "#!/usr/bin/env perl" shebang line 2013-05-23 04:41:22 +08:00
escape2.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape2n.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape3.go
escape4.go cmd/internal/gc: transitive inlining 2015-02-26 17:36:00 +00:00
escape5.go test: add tests for escape analysis of interface conversions 2015-03-28 16:15:27 +00:00
escape_array.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_calls.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_closure.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_field.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_iface.go test: add tests for escape analysis of interface conversions 2015-03-28 16:15:27 +00:00
escape_indir.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_level.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_map.go test: add tests for escape analysis of interface conversions 2015-03-28 16:15:27 +00:00
escape_param.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_slice.go test: add tests for escape analysis of slices 2015-03-28 13:18:42 +00:00
escape_struct_param1.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_struct_param2.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape_struct_return.go cmd/internal/gc: improve flow of input params to output params 2015-05-01 13:47:20 +00:00
escape.go
fibo.go Fix whitespace (use blanks consistently). 2014-12-08 22:22:58 +00:00
float_lit2.go test: fix two typos in float_lit2.go 2014-05-21 17:19:12 -04:00
float_lit3.go test/float_lit2.go: rewrite to test values near boundaries 2014-05-21 17:12:06 -04:00
float_lit.go
floatcmp.go
for.go
func1.go
func2.go
func3.go
func4.go
func5.go
func6.go
func7.go
func8.go
func.go
funcdup2.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
funcdup.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
gc1.go
gc2.go test: check for build constraints only upto the first blank line 2015-02-06 05:36:26 +00:00
gc.go
gcstring.go runtime: fix empty string handling in garbage collector 2014-03-11 23:58:39 -04:00
goprint.go
goprint.out
goto.go
helloworld.go
helloworld.out
if.go
import1.go test: match gccgo import error messages 2013-12-12 19:02:11 -08:00
import2.go
import4.go
import5.go
import.go
index0.go
index1.go
index2.go
index.go test: recognize gccgo error message in index.go 2013-09-27 20:38:52 -07:00
indirect1.go
indirect.go
init1.go test: deflake init1.go test, tighten its bounds 2015-02-13 22:13:56 +00:00
init.go
initcomma.go
initialize.go
initializerr.go
inline.go cmd/internal/gc: transitive inlining 2015-02-26 17:36:00 +00:00
int_lit.go
intcvt.go
iota.go
label1.go
label.go
linkx_run.go cmd/go: put user ldflags at the end of the linker invocation 2015-01-02 18:36:44 +00:00
linkx.go test: move linkx and sinit to run.go 2014-11-06 15:14:08 -05:00
literal.go
live1.go cmd/gc: correct liveness for fat variables 2014-02-15 10:58:55 -05:00
live2.go cmd/gc: allocate non-escaping maps on stack 2015-02-12 09:53:52 +00:00
live.go test: add -update_errors flag to run script 2015-04-10 11:33:42 +00:00
mallocfin.go
map1.go
map.go test/mapnan.go: add regression test for non-empty interfaces. 2014-08-06 17:02:55 -04:00
maplinear.go test: make maplinear more robust 2014-10-27 18:59:02 -04:00
method1.go
method2.go cmd/gc: fix method values whose receiver is an unnamed interface. 2013-08-29 10:00:58 +02:00
method3.go
method4.go
method5.go
method.go
named1.go cmd/gc: comma-ok assignments produce untyped bool as 2nd result 2014-08-11 16:11:55 -07:00
named.go
nil.go
nilcheck.go cmd/gc: optimize existence-only map lookups 2015-01-07 22:36:06 +00:00
nilptr2.go test: revert changes made for Go SSA interpreter test. 2013-10-08 14:36:20 -04:00
nilptr3.go cmd/7g: enable peephole optimizer 2015-04-08 08:16:54 +00:00
nilptr4.go cmd/gc: fix bad checknil with ints on 32 bit compilers 2014-02-26 12:25:13 -08:00
nilptr.go test/nilptr: add more tests 2013-09-05 23:06:34 -04:00
nosplit.go test: fix nosplit test for noopt build 2015-05-03 16:10:40 +00:00
nul1.go
parentype.go
peano.go
print.go runtime: move built-in print routines to go. 2014-07-31 13:48:48 -07:00
print.out runtime: move built-in print routines to go. 2014-07-31 13:48:48 -07:00
printbig.go
printbig.out
range.go cmd/gc: implement 'for range x {' 2014-07-16 19:27:10 -04:00
recover1.go
recover2.go
recover3.go tests: remove two misuses of nil pointers 2013-08-15 11:51:04 -04:00
recover4.go test: fix recover4 test on 64kb systems 2015-03-17 05:25:01 +00:00
recover.go test: add more cases to recover.go 2014-10-22 08:06:15 -07:00
rename1.go
rename.go
reorder2.go cmd/gc: shorten temporary lifetimes when possible 2014-04-01 13:31:38 -04:00
reorder.go
return.go test: add cases to return.go that gccgo got wrong 2013-08-07 11:31:01 -07:00
rotate0.go [dev.cc] test: disable rotate tests 2015-02-19 20:14:21 +00:00
rotate1.go [dev.cc] test: disable rotate tests 2015-02-19 20:14:21 +00:00
rotate2.go [dev.cc] test: disable rotate tests 2015-02-19 20:14:21 +00:00
rotate3.go [dev.cc] test: disable rotate tests 2015-02-19 20:14:21 +00:00
rotate.go
run.go test: gofmt run.go 2015-04-28 00:08:50 +00:00
rune.go
runtime.go
shift1.go test: avoid "declared but not used" errors in shift1.go 2014-07-20 12:25:24 -07:00
shift2.go test: add shift expression incorrectly rejected by gccgo. 2013-06-25 08:06:34 +02:00
sieve.go
sigchld.go test: skip SIGCHLD test on Plan 9 2014-01-29 09:28:23 +01:00
sigchld.out
simassign.go
sinit_run.go test: fix nacl build 2014-11-09 21:10:49 -05:00
sinit.go test: move linkx and sinit to run.go 2014-11-06 15:14:08 -05:00
sizeof.go test: correct sizeof.go. 2013-06-02 19:10:11 +02:00
slice3.go cmd/gc, runtime: treat slices and strings like pointers in garbage collection 2014-08-25 14:38:19 -04:00
slice3err.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
slicecap.go cmd/gc, runtime: treat slices and strings like pointers in garbage collection 2014-08-25 14:38:19 -04:00
sliceopt.go cmd/internal/gc: optimize append + write barrier 2015-05-12 17:55:09 +00:00
solitaire.go
stack.go
string_lit.go test: add []rune case to string_lit.go 2013-12-12 17:17:02 -08:00
stringrange.go
struct0.go
switch3.go
switch4.go
switch.go
tinyfin.go runtime: combine small NoScan allocations 2014-01-24 22:35:11 +04:00
torture.go cmd/8g: don't allocate a register early for cap(CHAN). 2014-07-01 09:20:51 +02:00
turing.go
typecheck.go cmd/gc: silence assignment errors to undefined symbols 2014-01-03 21:03:20 +01:00
typeswitch1.go
typeswitch2.go
typeswitch3.go
typeswitch.go
undef.go
utf.go
varerr.go
varinit.go
writebarrier.go cmd/internal/gc: optimize append + write barrier 2015-05-12 17:55:09 +00:00
zerodivide.go