Skip to content
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: eliminate write barrier for self-referencing pointer #15238

Open
randall77 opened this issue Apr 11, 2016 · 2 comments
Open

cmd/compile: eliminate write barrier for self-referencing pointer #15238

randall77 opened this issue Apr 11, 2016 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@randall77
Copy link
Contributor

Go code often does something like:

type Buffer struct {
   buf []byte
   bootstrap [64]byte
}
var b *Buffer = ...
b.buf = b.bootstrap[:]

I don't think we need a write barrier when we write the slice pointer into b.buf, because the pointer always points from an object into (part of) itself.

But see the discussion in #14855 . Writing a pointer to the heap without a write barrier is tricky in the presence of races. Make sure the arguments in that issue don't apply here (I don't think they do, writing a self-pointer is like writing nil).

@aclements

@randall77 randall77 added this to the Unplanned milestone Apr 11, 2016
@aclements
Copy link
Member

How much do you think this would actually win? Rick and I just spent half an hour debating whether it was actually safe to ignore write barriers for writes of nil in the presence of concurrent stack rescanning (which we don't do yet, but are considering). We eventually decided it was, but things like that make me weary of subtle write barrier optimizations.

@randall77
Copy link
Contributor Author

I'm not sure. The SSA compiler does it a lot (in cmd/compile/internal/ssa/value.go), but it is probably an outlier.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

3 participants