Skip to content

perf: use value type instead of pointer - #177

Open
proost wants to merge 1 commit into
apache:mainfrom
proost:perf-change-to-value-types
Open

proost wants to merge 1 commit into
apache:mainfrom
proost:perf-change-to-value-types

Conversation

@proost

@proost proost commented Sep 5, 2026

Copy link
Copy Markdown
Member

Current "GetFrequentItems" returned slice of pointers. It makes large heap allocations and finally this lead to huge GC overhead.

I propose use value type instead.

Here is benchmark:

goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/frequencies
cpu: Apple M4 Pro
BenchmarkSortItems_Row_Pointer
BenchmarkSortItems_Row_Pointer/size=10
BenchmarkSortItems_Row_Pointer/size=10-12         	 4225843	       276.6 ns/op	     568 B/op	      15 allocs/op
BenchmarkSortItems_Row_Pointer/size=100
BenchmarkSortItems_Row_Pointer/size=100-12        	  370392	      2956 ns/op	    5368 B/op	     108 allocs/op
BenchmarkSortItems_Row_Pointer/size=1000
BenchmarkSortItems_Row_Pointer/size=1000-12       	   34378	     33689 ns/op	   49528 B/op	    1011 allocs/op
BenchmarkSortItems_Row_Pointer/size=10000
BenchmarkSortItems_Row_Pointer/size=10000-12      	    2156	    518306 ns/op	  630392 B/op	   10018 allocs/op
PASS


goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/frequencies
cpu: Apple M4 Pro
BenchmarkSortItems_Row_Value
BenchmarkSortItems_Row_Value/size=10
BenchmarkSortItems_Row_Value/size=10-12         	 8494632	       124.3 ns/op	     320 B/op	       1 allocs/op
BenchmarkSortItems_Row_Value/size=100
BenchmarkSortItems_Row_Value/size=100-12        	  574056	      1867 ns/op	    3200 B/op	       1 allocs/op
BenchmarkSortItems_Row_Value/size=1000
BenchmarkSortItems_Row_Value/size=1000-12       	   56760	     20631 ns/op	   32768 B/op	       1 allocs/op
BenchmarkSortItems_Row_Value/size=10000
BenchmarkSortItems_Row_Value/size=10000-12      	    2941	    355211 ns/op	  327680 B/op	       1 allocs/op
PASS

goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/frequencies
cpu: Apple M4 Pro
BenchmarkSortItems_RowItem_Pointer
BenchmarkSortItems_RowItem_Pointer/size=10
BenchmarkSortItems_RowItem_Pointer/size=10-12         	 3026780	       390.7 ns/op	     728 B/op	      15 allocs/op
BenchmarkSortItems_RowItem_Pointer/size=100
BenchmarkSortItems_RowItem_Pointer/size=100-12        	  268033	      4498 ns/op	    6968 B/op	     108 allocs/op
BenchmarkSortItems_RowItem_Pointer/size=1000
BenchmarkSortItems_RowItem_Pointer/size=1000-12       	   23358	     50842 ns/op	   65528 B/op	    1011 allocs/op
BenchmarkSortItems_RowItem_Pointer/size=10000
BenchmarkSortItems_RowItem_Pointer/size=10000-12      	    1527	    758682 ns/op	  790403 B/op	   10018 allocs/op
PASS

goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/frequencies
cpu: Apple M4 Pro
BenchmarkSortItems_RowItem_Value
BenchmarkSortItems_RowItem_Value/size=10
BenchmarkSortItems_RowItem_Value/size=10-12         	 4171860	       274.2 ns/op	     416 B/op	       1 allocs/op
BenchmarkSortItems_RowItem_Value/size=100
BenchmarkSortItems_RowItem_Value/size=100-12        	  326707	      3848 ns/op	    4096 B/op	       1 allocs/op
BenchmarkSortItems_RowItem_Value/size=1000
BenchmarkSortItems_RowItem_Value/size=1000-12       	   27349	     43786 ns/op	   40960 B/op	       1 allocs/op
BenchmarkSortItems_RowItem_Value/size=10000
BenchmarkSortItems_RowItem_Value/size=10000-12      	    1557	    719896 ns/op	  401409 B/op	       1 allocs/op
PASS

Problem is this is BREAKING CHANGE. But acceptable.

  1. this project is under development.
  2. Users can't aware changes. Because usually use with "for" loop. So it doesn't change any for loop logic. And all fields is private. Either pointer type or value type, user can access using Getter only.

@proost proost self-assigned this Sep 5, 2026
@proost

proost commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

@freakyzoidberg
Can you review this? This PR accompany breaking changes.

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.

1 participant