New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: don't emit writebarrier for stores to newly allocated objects #9755
Comments
I've calculated an optimistic approximation of the potential win by counting runtime.writebarrier calls right after runtime.newobject calls w/o any intervening calls in godoc binary. |
I'm not sure the gain is as large as you imply with your 25% number. If the On Mon, Feb 2, 2015 at 12:23 PM, Dmitry Vyukov notifications@github.com
|
The compiler now emits the needWriteBarrier check. I think that's enough for Go 1.5. We can revisit this if and when profiles show that we're spending too much time on things like this. |
This is fixed now; the following code has no write barriers:
|
Consider the following code:
x := &X{&obj, make([]int, n)}
...
Compiler transforms it to roughly the following code:
tmp0 := runtime.makeslice(int, n)
tmp1 := runtime.newobject(X)
runtime.writebarrierptr(&tmp1.f0, &obj)
runtime.writebarrierslice(&tmp1.f2, tmp0)
I suspect that barriers are unnecessary in this case because tmp1 is accessible only through the stack of the current goroutine. So &obj and tmp0 will be found and marked during stack scanning.
It seems that a simple approximation of the "is accessible only through the stack of the current goroutine" condition is "we have not yet encountered any calls since allocation of the object". That is:
tmp1 := runtime.newobject(X)
tmp1.f0 = ... // no write barrier
tmp1.f1 = ... // no write barrier
any function call
tmp1.f0 = ... // write barrier
tmp1.f2 = ... // write barrier
The text was updated successfully, but these errors were encountered: