Skip to content

Some optimization for LZ4 compression#48

Merged
darkweak merged 2 commits intodarkweak:mainfrom
everyx:perf/lz4-write-optimization
Mar 13, 2026
Merged

Some optimization for LZ4 compression#48
darkweak merged 2 commits intodarkweak:mainfrom
everyx:perf/lz4-write-optimization

Conversation

@everyx
Copy link
Copy Markdown
Contributor

@everyx everyx commented Feb 28, 2026

Changes

  1. Replace ReadFrom with Write - Avoid unnecessary bytes.Reader allocation
    - Changed from writer.ReadFrom(bytes.NewReader(value)) to writer.Write(value)
    - Applied to all 9 storage providers: badger, etcd, go-redis, nats, nuts, olric, otter, redis, simplefs
  2. Move LZ4 compression outside Badger transaction - Reduce lock contention
    - Compression is CPU-intensive and was previously done inside the Badger Update transaction
    - Moved compression before the transaction to avoid holding the database lock during compression

@everyx everyx changed the title Perf/lz4 write optimization Some optimization for LZ4 compression Feb 28, 2026
@darkweak
Copy link
Copy Markdown
Owner

Hello @everyx can you fix the lint issues? make golangci-lint

@everyx everyx force-pushed the perf/lz4-write-optimization branch from 095bc20 to b937c88 Compare March 13, 2026 00:33
@everyx
Copy link
Copy Markdown
Contributor Author

everyx commented Mar 13, 2026

@darkweak Done.

everyx added 2 commits March 13, 2026 08:49
Replace writer.ReadFrom(bytes.NewReader(value)) with writer.Write(value)
across all 9 storage providers to avoid unnecessary bytes.Reader allocation.
Move LZ4 compression to outside of the Badger Update transaction
to avoid holding the database lock during CPU-intensive compression.
@everyx everyx force-pushed the perf/lz4-write-optimization branch from b937c88 to 95b8c73 Compare March 13, 2026 00:50
@darkweak darkweak merged commit 171dcba into darkweak:main Mar 13, 2026
9 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