feat(gslice): initial set capacity for union#31
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #31 +/- ##
==========================================
+ Coverage 96.36% 96.42% +0.05%
==========================================
Files 34 34
Lines 3823 3828 +5
==========================================
+ Hits 3684 3691 +7
+ Misses 96 95 -1
+ Partials 43 42 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
856c7e6 to
b2ddeb5
Compare
SilverRainZ
reviewed
Dec 23, 2025
| ret := S{} // TODO: Guess a cap. | ||
| size := Sum(Map(ss, func(s S) int { return len(s) })) | ||
| members := set.NewWithCap[T](size) | ||
| ret := make(S, 0, size/2) |
Collaborator
There was a problem hiding this comment.
Can you please add a benchmark for this?
Collaborator
Author
There was a problem hiding this comment.
go test ./gslice -bench=BenchmarkUnion -benchmem
goos: darwin
goarch: arm64
pkg: github.com/bytedance/gg/gslice
cpu: Apple M4 Pro
BenchmarkUnion/new-union-diff-2-10-14 3053234 373.5 ns/op 944 B/op 8 allocs/op
BenchmarkUnion/old-union-diff-2-10-14 2819313 412.5 ns/op 1744 B/op 10 allocs/op
BenchmarkUnion/new-union-diff-5-100-14 178990 6407 ns/op 24736 B/op 8 allocs/op
BenchmarkUnion/old-union-diff-5-100-14 73288 16443 ns/op 44624 B/op 22 allocs/op
BenchmarkUnion/new-union-same-2-10-14 5271890 218.1 ns/op 784 B/op 7 allocs/op
BenchmarkUnion/old-union-same-2-10-14 5344665 226.7 ns/op 1248 B/op 5 allocs/op
BenchmarkUnion/new-union-same-5-100-14 368089 3117 ns/op 20640 B/op 7 allocs/op
BenchmarkUnion/old-union-same-5-100-14 603517 2002 ns/op 1248 B/op 5 allocs/op
BenchmarkUnion/new-union-half-2-100-14 668262 1811 ns/op 5888 B/op 7 allocs/op
BenchmarkUnion/old-union-half-2-100-14 415273 2723 ns/op 5616 B/op 14 allocs/op
SilverRainZ
reviewed
Dec 26, 2025
| // 3. half different | ||
| ss5 := [][]int{ | ||
| Range(0, 100), | ||
| Range(0, 100), |
Collaborator
There was a problem hiding this comment.
Should be (50, 150) here?
| ret := S{} // TODO: Guess a cap. | ||
| size := Sum(Map(ss, func(s S) int { return len(s) })) | ||
| members := set.NewWithCap[T](size) | ||
| ret := make(S, 0, size/2) |
SilverRainZ
reviewed
Dec 27, 2025
SilverRainZ
approved these changes
Dec 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.