Skip to content

perf: reduce temp allocation in serialization - #178

Merged
proost merged 1 commit into
apache:mainfrom
proost:perf-reduce-temp-allocation
Sep 5, 2026
Merged

perf: reduce temp allocation in serialization#178
proost merged 1 commit into
apache:mainfrom
proost:perf-reduce-temp-allocation

Conversation

@proost

@proost proost commented Sep 5, 2026

Copy link
Copy Markdown
Member

During Serialization, temporary allocations happens due to collecting active values and active keys.

But we can remove those allocations and reduce 4 loops to one.

main branch:

goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/frequencies
cpu: Apple M4 Pro
BenchmarkLongsSketchToSlice
BenchmarkLongsSketchToSlice/active=48
BenchmarkLongsSketchToSlice/active=48-12         	 4521978	       262.5 ns/op	    1664 B/op	       3 allocs/op
BenchmarkLongsSketchToSlice/active=768
BenchmarkLongsSketchToSlice/active=768-12        	  344616	      3540 ns/op	   25856 B/op	       3 allocs/op
BenchmarkLongsSketchToSlice/active=12288
BenchmarkLongsSketchToSlice/active=12288-12      	   20967	     56307 ns/op	  401410 B/op	       3 allocs/op
BenchmarkLongsSketchToSlice/active=196608
BenchmarkLongsSketchToSlice/active=196608-12     	    1006	   1112128 ns/op	 6299650 B/op	       3 allocs/op
PASS

This PR:

goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/frequencies
cpu: Apple M4 Pro
BenchmarkLongsSketchToSlice
BenchmarkLongsSketchToSlice/active=48
BenchmarkLongsSketchToSlice/active=48-12         	 9544124	       126.4 ns/op	     896 B/op	       1 allocs/op
BenchmarkLongsSketchToSlice/active=768
BenchmarkLongsSketchToSlice/active=768-12        	  701419	      1667 ns/op	   13568 B/op	       1 allocs/op
BenchmarkLongsSketchToSlice/active=12288
BenchmarkLongsSketchToSlice/active=12288-12      	   38566	     31243 ns/op	  204803 B/op	       1 allocs/op
BenchmarkLongsSketchToSlice/active=196608
BenchmarkLongsSketchToSlice/active=196608-12     	    2101	    559105 ns/op	 3153921 B/op	       1 allocs/op
PASS

@proost proost self-assigned this Sep 5, 2026
@proost
proost merged commit 403da63 into apache:main Sep 5, 2026
5 checks passed
@proost
proost deleted the perf-reduce-temp-allocation branch September 5, 2026 08:29
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