Skip to content

Commit 13cd006

Browse files
committed
runtime: add fast version of getArgInfo
getArgInfo is called a lot during stack copying. In the common case it doesn't do much work, but it cannot be inlined. This change works around that. name old time/op new time/op delta StackCopyPtr-8 108ms ± 5% 96ms ± 4% -10.40% (p=0.000 n=20+20) StackCopy-8 82.6ms ± 3% 78.4ms ± 6% -5.15% (p=0.000 n=19+20) StackCopyNoCache-8 130ms ± 3% 122ms ± 3% -6.44% (p=0.000 n=20+20) Change-Id: If7d8a08c50a4e2e76e4331b399396c5dbe88c2ce Reviewed-on: https://go-review.googlesource.com/108945 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
1 parent 0fd427f commit 13cd006

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/cmd/compile/internal/gc/inl_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func TestIntendedInlining(t *testing.T) {
4949
"fastrand",
5050
"float64bits",
5151
"funcPC",
52+
"getArgInfoFast",
5253
"getm",
5354
"isDirectIface",
5455
"itabHashFunc",

src/runtime/traceback.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func tracebackdefers(gp *g, callback func(*stkframe, unsafe.Pointer) bool, v uns
6767
}
6868
frame.fn = f
6969
frame.argp = uintptr(deferArgs(d))
70-
frame.arglen, frame.argmap = getArgInfo(&frame, f, true, fn)
70+
var ok bool
71+
frame.arglen, frame.argmap, ok = getArgInfoFast(f, true)
72+
if !ok {
73+
frame.arglen, frame.argmap = getArgInfo(&frame, f, true, fn)
74+
}
7175
}
7276
frame.continpc = frame.pc
7377
if !callback((*stkframe)(noescape(unsafe.Pointer(&frame))), v) {
@@ -279,7 +283,11 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
279283
// metadata recorded by f's caller.
280284
if callback != nil || printing {
281285
frame.argp = frame.fp + sys.MinFrameSize
282-
frame.arglen, frame.argmap = getArgInfo(&frame, f, callback != nil, nil)
286+
var ok bool
287+
frame.arglen, frame.argmap, ok = getArgInfoFast(f, callback != nil)
288+
if !ok {
289+
frame.arglen, frame.argmap = getArgInfo(&frame, f, callback != nil, nil)
290+
}
283291
}
284292

285293
// Determine frame's 'continuation PC', where it can continue.
@@ -546,6 +554,15 @@ type reflectMethodValue struct {
546554
stack *bitvector // args bitmap
547555
}
548556

557+
// getArgInfoFast returns the argument frame information for a call to f.
558+
// It is short and inlineable. However, it does not handle all functions.
559+
// If ok reports false, you must call getArgInfo instead.
560+
// TODO(josharian): once we do mid-stack inlining,
561+
// call getArgInfo directly from getArgInfoFast and stop returning an ok bool.
562+
func getArgInfoFast(f funcInfo, needArgMap bool) (arglen uintptr, argmap *bitvector, ok bool) {
563+
return uintptr(f.args), nil, !(needArgMap && f.args == _ArgsSizeUnknown)
564+
}
565+
549566
// getArgInfo returns the argument frame information for a call to f
550567
// with call frame frame.
551568
//

0 commit comments

Comments
 (0)