mirror of
https://github.com/golang/go.git
synced 2025-05-19 22:33:25 +00:00
runtime: call mallocgc directly from makeslice and growslice
The extra checks provided by newarray are redundant in these cases. This shrinks by one frame the call stack expected by the pprof test. name old time/op new time/op delta MakeSlice-8 34.3ns ± 2% 30.5ns ± 3% -11.03% (p=0.000 n=24+22) GrowSlicePtr-8 134ns ± 2% 129ns ± 3% -3.25% (p=0.000 n=25+24) Change-Id: Icd828655906b921c732701fd9d61da3fa217b0af Reviewed-on: https://go-review.googlesource.com/22276 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
7b0ba1cff8
commit
0150f15a92
@ -82,7 +82,7 @@ func TestMemoryProfiler(t *testing.T) {
|
|||||||
# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:61
|
# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:61
|
||||||
`, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),
|
`, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),
|
||||||
|
|
||||||
fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
|
fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
|
||||||
# 0x[0-9,a-f]+ runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:27
|
# 0x[0-9,a-f]+ runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:27
|
||||||
# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:62
|
# 0x[0-9,a-f]+ runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/runtime/pprof/mprof_test.go:62
|
||||||
`, memoryProfilerRun, (2<<20)*memoryProfilerRun),
|
`, memoryProfilerRun, (2<<20)*memoryProfilerRun),
|
||||||
|
@ -55,7 +55,12 @@ func makeslice(t *slicetype, len64, cap64 int64) slice {
|
|||||||
panic(errorString("makeslice: cap out of range"))
|
panic(errorString("makeslice: cap out of range"))
|
||||||
}
|
}
|
||||||
|
|
||||||
p := newarray(t.elem, uintptr(cap))
|
et := t.elem
|
||||||
|
var flags uint32
|
||||||
|
if et.kind&kindNoPointers != 0 {
|
||||||
|
flags = flagNoScan
|
||||||
|
}
|
||||||
|
p := mallocgc(et.size*uintptr(cap), et, flags)
|
||||||
return slice{p, len, cap}
|
return slice{p, len, cap}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +135,7 @@ func growslice(t *slicetype, old slice, cap int) slice {
|
|||||||
memclr(add(p, lenmem), capmem-lenmem)
|
memclr(add(p, lenmem), capmem-lenmem)
|
||||||
} else {
|
} else {
|
||||||
// Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory.
|
// Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory.
|
||||||
p = newarray(et, uintptr(newcap))
|
p = mallocgc(capmem, et, 0)
|
||||||
if !writeBarrier.enabled {
|
if !writeBarrier.enabled {
|
||||||
memmove(p, old.array, lenmem)
|
memmove(p, old.array, lenmem)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user