Skip to content

perf(compressor): reduce memory by using new compression code#1040

Merged
SpencerTorres merged 1 commit intomainfrom
compressor_etc
Feb 13, 2025
Merged

perf(compressor): reduce memory by using new compression code#1040
SpencerTorres merged 1 commit intomainfrom
compressor_etc

Conversation

@SpencerTorres
Copy link
Copy Markdown
Member

Summary

#1039 included some code to reduce memory usage when initializing the compressor. After further review of ch-go and clickhouse-go, it seems only ONE compression method is ever used per connection. With this in mind I have refactored and simplified the code.

The most important line of this PR is to actually USE the optimization from #1039:

compressor:  compress.NewWriter(compress.Level(opt.CompressionLevel), compressionMethod),

but in addition to this I have updated some functions and constants to reflect the actual usage patterns for compression.
*Writer.Compress() no longer takes a Method since this is known during initialization and does not change.

I don't believe this is a breaking change since these packages/constants are only used internally. The compression code is abstracted by the opt.Compression and opt.CompressionLevel options.

I have also re-run the benchmarks and this code is negligibly faster by ~100ns.

Let me know if I'm wrong about the usage of any of this code. Thanks!

Checklist

  • Unit and integration tests covering the common scenarios were added

@SpencerTorres SpencerTorres merged commit aadb7ee into main Feb 13, 2025
19 checks passed
@SpencerTorres SpencerTorres deleted the compressor_etc branch February 13, 2025 18:43
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