-
Notifications
You must be signed in to change notification settings - Fork 10
compact: add Make methods for compact ranges #174
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
base: main
Are you sure you want to change the base?
Conversation
The New* methods unnecessarily allocate. If the user needs a pointer, they can convert, but most users only need it by value.
For reviewers: I don't feel strongly about this PR, but thought I'd throw it in for consideration. Been using this package for a side-project, and figured why not remove an allocation. The current state is safer / avoids some footguns by design. So it's conceivable that it should stay this way. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #174 +/- ##
===========================================
- Coverage 89.33% 58.18% -31.16%
===========================================
Files 7 8 +1
Lines 497 782 +285
===========================================
+ Hits 444 455 +11
- Misses 48 322 +274
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Pavel I intend to review this by the end of the week. I've just returned from vacation and need to get up to speed before deciding whether this subtle variation is worth the extra API method or not. Thanks for sending it!
@mhutchinson nvm, I think Go optimizes the allocation out if we say diff --git a/compact/range_test.go b/compact/range_test.go
index 53bf58a..998c0cc 100644
--- a/compact/range_test.go
+++ b/compact/range_test.go
@@ -578,10 +578,10 @@ func TestDecomposePow2(t *testing.T) {
func BenchmarkNewRange(b *testing.B) {
b.ReportAllocs()
- var cr *compact.Range
+ var cr compact.Range
for range b.N {
- // BenchmarkNewRange-10 69894982 17.13 ns/op 48 B/op 1 allocs/op
- cr = factory.NewEmptyRange(10)
+ // BenchmarkNewRange-10 1000000000 0.3165 ns/op 0 B/op 0 allocs/op
+ cr = *factory.NewEmptyRange(10)
}
_ = cr
}
|
I'll remove the API changes, and reduce this PR just to a bit of commenting in |
The
New*
methods unnecessarily allocate. If the user needs a pointer, they can convert, but most users probably only need it by value.