Skip to content

feat(gslice): initial set capacity for union#31

Merged
XQ-Gang merged 3 commits into
mainfrom
feat/initial_union_set
Dec 29, 2025
Merged

feat(gslice): initial set capacity for union#31
XQ-Gang merged 3 commits into
mainfrom
feat/initial_union_set

Conversation

@XQ-Gang
Copy link
Copy Markdown
Collaborator

@XQ-Gang XQ-Gang commented Dec 22, 2025

No description provided.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.42%. Comparing base (b75d7d3) to head (b24a7b7).
⚠️ Report is 2 commits behind head on main.

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     
Flag Coverage Δ
go-1.18.x 95.72% <100.00%> (+0.24%) ⬆️
go-1.19.x 95.36% <100.00%> (-0.08%) ⬇️
go-1.20.x 96.00% <100.00%> (+0.10%) ⬆️
go-1.21.x 96.10% <100.00%> (+0.10%) ⬆️
go-1.22.x 95.79% <100.00%> (-0.13%) ⬇️
go-1.23.x 96.13% <100.00%> (+0.16%) ⬆️
go-1.24.x 95.92% <100.00%> (-0.21%) ⬇️
unittests 96.42% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@XQ-Gang XQ-Gang force-pushed the feat/initial_union_set branch from 856c7e6 to b2ddeb5 Compare December 22, 2025 12:47
@XQ-Gang XQ-Gang changed the title feat(gslice): initial set for union feat(gslice): initial set capacity for union Dec 22, 2025
@XQ-Gang XQ-Gang requested a review from SilverRainZ December 23, 2025 12:37
Comment thread gslice/gslice.go
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a benchmark for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@XQ-Gang XQ-Gang requested a review from SilverRainZ December 25, 2025 07:54
Comment thread gslice/gslice_bench_test.go Outdated
// 3. half different
ss5 := [][]int{
Range(0, 100),
Range(0, 100),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be (50, 150) here?

Comment thread gslice/gslice.go
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread gslice/gslice_bench_test.go Outdated
@XQ-Gang XQ-Gang merged commit 964b2cc into main Dec 29, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants