Skip to content

Comments

Short circuit async#15

Merged
scunningham merged 4 commits intoprequel-dev:mainfrom
scunningham:short_circuit_async
Jan 31, 2026
Merged

Short circuit async#15
scunningham merged 4 commits intoprequel-dev:mainfrom
scunningham:short_circuit_async

Conversation

@scunningham
Copy link
Contributor

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request optimizes the async writer for small payloads by deferring the creation of async goroutines until they're actually needed. It also removes the external gammazero/workerpool dependency and replaces it with a custom, lightweight worker pool implementation.

Changes:

  • Introduced a custom worker pool implementation in internal/pkg/wpool to replace the external dependency
  • Modified async writer to defer async task creation until a second block is needed, using synchronous compression for single-block payloads
  • Added comprehensive tests for user-provided dictionaries with both linked and independent block modes
  • Added comparative benchmarks between plz4 and lz4 libraries
  • Optimized bakeoff benchmark execution order to reduce cache penalties

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/pkg/wpool/wpool.go New custom worker pool implementation with dynamic scaling, idle worker cleanup, and panic recovery
internal/pkg/wpool/wpool_test.go Comprehensive test suite for worker pool functionality including concurrency, GC, panic handling
internal/pkg/async/writer.go Short-circuit optimization: defer async tasks until second block, use sync path for small payloads
internal/pkg/async/reader.go Limit decompression tasks based on content size when known
internal/pkg/compress/compress.go Added documentation for Compressor interface
internal/test/wr_test.go Added dictionary application tests, updated worker pool API usage
internal/test/wr_bench_test.go Added comparative benchmarks between plz4 and lz4
internal/test/rd_test.go Added test case with max parallel setting
internal/test/block_test.go Enhanced compression benchmarks with multiple input sizes and levels
cmd/plz4/internal/ops/bakeoff.go Reversed benchmark execution order to reduce cache penalties, removed worker pool usage
go.mod, go.sum Removed gammazero/workerpool dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Run tests in reverse order so slowest samples run first.  This prevents
skewing of results on the fatest samples due to caching effects.
- Remove the worker pool; spawning goroutines is faster.
When reading or writing data asynchronously, if the operation can be
completed immediately (i.e., without blocking), we now short-circuit the
process. This optimization reduces latency and improves throughput for
scenarios where data is readily available.
@scunningham scunningham requested a review from aleksmaus January 28, 2026 16:53
@scunningham scunningham marked this pull request as ready for review January 28, 2026 16:53
@@ -171,7 +172,7 @@ func benchmarkWrite(b *testing.B, sz int, opts ...Option) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

Choose a reason for hiding this comment

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

nit: could "modernize"
was used in the different file as

for b.Loop() {

@scunningham scunningham merged commit bc81d75 into prequel-dev:main Jan 31, 2026
3 checks passed
@scunningham scunningham deleted the short_circuit_async branch January 31, 2026 15:01
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