Skip to content
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

feat: implement extra compressed chunks #3

Merged
merged 1 commit into from
May 13, 2024

Conversation

smira
Copy link
Member

@smira smira commented May 2, 2024

This allows to keep more data in the circular buffer by compressing old
chunks and keeping them around, so the overall memory consumption is
smaller.

Change is backwards compatible - by default compression is not used.

Tests were refactored to use regular *testing.T.

Added benchmarks for read and write operations.

Writes are allocation-free, even when using compression (compression
buffer is re-used):

goos: linux
goarch: amd64
pkg: github.com/siderolabs/go-circular
cpu: AMD Ryzen 9 5950X 16-Core Processor
BenchmarkWrite/defaults-32         	 7848931	       150.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkWrite/growing_buffer-32   	 7116709	       144.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkWrite/compression-32      	 3042698	       399.2 ns/op	       0 B/op	       0 allocs/op

Reads are not allocation-free, but each Reader has fixed allocation cost
(decompression buffer is re-used):

goos: linux
goarch: amd64
pkg: github.com/siderolabs/go-circular
cpu: AMD Ryzen 9 5950X 16-Core Processor
BenchmarkRead/defaults-32         	   99565	     12682 ns/op	      80 B/op	       1 allocs/op
BenchmarkRead/growing_buffer-32   	   88371	     12327 ns/op	      80 B/op	       1 allocs/op
BenchmarkRead/compression-32      	    3193	    372417 ns/op	  139425 B/op	       3 allocs/op

@smira smira marked this pull request as draft May 2, 2024 15:03
This allows to keep more data in the circular buffer by compressing old
chunks and keeping them around, so the overall memory consumption is
smaller.

Change is backwards compatible - by default compression is not used.

Tests were refactored to use regular *testing.T.

Added benchmarks for read and write operations.

Writes are allocation-free, even when using compression (compression
buffer is re-used):

```
goos: linux
goarch: amd64
pkg: github.com/siderolabs/go-circular
cpu: AMD Ryzen 9 5950X 16-Core Processor
BenchmarkWrite/defaults-32         	 7848931	       150.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkWrite/growing_buffer-32   	 7116709	       144.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkWrite/compression-32      	 3042698	       399.2 ns/op	       0 B/op	       0 allocs/op
```

Reads are not allocation-free, but each Reader has fixed allocation cost
(decompression buffer is re-used):

```
goos: linux
goarch: amd64
pkg: github.com/siderolabs/go-circular
cpu: AMD Ryzen 9 5950X 16-Core Processor
BenchmarkRead/defaults-32         	   99565	     12682 ns/op	      80 B/op	       1 allocs/op
BenchmarkRead/growing_buffer-32   	   88371	     12327 ns/op	      80 B/op	       1 allocs/op
BenchmarkRead/compression-32      	    3193	    372417 ns/op	  139425 B/op	       3 allocs/op
```

Co-authored-by: Utku Ozdemir <[email protected]>
Signed-off-by: Andrey Smirnov <[email protected]>
@smira smira marked this pull request as ready for review May 8, 2024 15:02
@smira smira requested a review from utkuozdemir May 8, 2024 15:02
Copy link
Member

@utkuozdemir utkuozdemir left a comment

Choose a reason for hiding this comment

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

🔥

@smira
Copy link
Member Author

smira commented May 13, 2024

/m

@talos-bot talos-bot merged commit 3c48c53 into siderolabs:main May 13, 2024
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.

3 participants