-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
storage: remove pointers from allocator returns #11206
Conversation
I'm missing the motivation for this change. Returning a pointer nicely captures the optionality of the return value. And returning the structure is actually a pessimization as it consumes more stack space (which isn't a big deal for this code, but still). Review status: 0 of 4 files reviewed at latest revision, all discussions resolved, all commit checks successful. Comments from Reviewable |
Reviewed 4 of 4 files at r1. pkg/storage/allocator.go, line 250 at r1 (raw file):
why not propagate the move to values to pkg/storage/allocator.go, line 382 at r1 (raw file):
why the unusual order of returns? pkg/storage/allocator.go, line 483 at r1 (raw file):
why not propagate the move to values to pkg/storage/allocator_test.go, line 313 at r1 (raw file):
Comments from Reviewable |
Specifically, remove them from RebalanceTarget and AllocateTarget. Part of cockroachdb#10275.
bacffff
to
1e7b222
Compare
Unless I'm mistaken, using a pointer to show that a value was retrieved or not is considered a go anti-pattern and the preferred pattern is to return a boolean as well. Review status: 0 of 5 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. pkg/storage/allocator.go, line 250 at r1 (raw file): Previously, tamird (Tamir Duberstein) wrote…> why not propagate the move to values to `selectGood`?pkg/storage/allocator.go, line 382 at r1 (raw file): Previously, tamird (Tamir Duberstein) wrote…> why the unusual order of returns?pkg/storage/allocator.go, line 483 at r1 (raw file): Previously, tamird (Tamir Duberstein) wrote…> why not propagate the move to values to `improve`?pkg/storage/allocator_test.go, line 313 at r1 (raw file): Previously, tamird (Tamir Duberstein) wrote…> `result != (roachpb.ReplicaDescriptor{})`Comments from Reviewable |
I'm not aware of that. The Go stdlib certainly uses sentinels instead of a separate return value in various places. For example, |
Review status: 0 of 5 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. pkg/storage/allocator_test.go, line 313 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…> Had to use deepEqual. :(Comments from Reviewable |
I think those examples from the standard library aren't exactly canon - there's a lot of junk in the stdlib that was written early and can't be changed. That said, I'm also thumbs down on this as-written for reasons elaborated on in another comment. Reviewed 5 of 5 files at r2. pkg/storage/allocator.go, line 484 at r2 (raw file):
isn't this equivalent to
pkg/storage/allocator_test.go, line 313 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…> Yet another reason against this change.pkg/storage/balancer.go, line 42 at r2 (raw file):
another example of an interface that would need to change if this were to move to values - you'd probably want to pass pkg/storage/balancer.go, line 103 at r2 (raw file):
pkg/storage/balancer.go, line 115 at r2 (raw file):
this is odd. Comments from Reviewable |
No, those examples aren't canon and neither is the stdlib, but returning pointers is very common. I don't think we should be changing code like this unless there is a very compelling reason. For example, a Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. Comments from Reviewable |
Yes, that's a sensible argument. I don't particularly feel strongly about
this change one way or the other, but I wanted to enumerate the rationale
one might consider.
…On Nov 23, 2016 20:30, "Peter Mattis" ***@***.***> wrote:
I think those examples from the standard library aren't exactly canon -
there's a lot of junk in the stdlib that was written early and can't be
changed.
No, those examples aren't canon and neither is the stdlib, but returning
pointers is very common. I don't think we should be changing code like this
unless there is a very compelling reason. For example, a nil return value
doesn't make sense or returning a pointer incurs an allocation which has
been shown to be costly via profiling.
------------------------------
Review status: all files reviewed at latest revision, 5 unresolved
discussions, some commit checks failed.
------------------------------
*Comments from Reviewable
<https://reviewable.io:443/reviews/cockroachdb/cockroach/11206#-:-KXIwdti3X89sSV0b-OW:b-yww06z>*
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#11206 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABdsPE1PelDxv3o5BTHxYYhNrCWTJArZks5rBOjHgaJpZM4K65dV>
.
|
ok, I'm going to close this. Maybe revisit it once the rest of the changes to allocator are complete. |
Specifically, remove them from RebalanceTarget and AllocateTarget.
Part of #10275.
This change is