Skip to content

Release GVL during Zstd.decompress to enable multi-threaded decompression#133

Closed
SpringMT wants to merge 1 commit intomainfrom
release-gvl-during-decompress
Closed

Release GVL during Zstd.decompress to enable multi-threaded decompression#133
SpringMT wants to merge 1 commit intomainfrom
release-gvl-during-decompress

Conversation

@SpringMT
Copy link
Owner

@SpringMT SpringMT commented Mar 1, 2026

Summary

This PR fixes the multi-threaded decompression performance issue by releasing the GVL (Global VM Lock) during Zstd.decompress operations.

Changes

  • Modified decode_one_frame in ext/zstdruby/zstdruby.c to use zstd_stream_decompress with GVL release instead of calling ZSTD_decompressStream directly
  • This allows multiple Ruby threads to decompress independent data in parallel

Performance Improvement

Before (with GVL held):

THREADS=4: 0.95s user / ~1.4s real (CPU ~100%, single-threaded)

After (with GVL released):

THREADS=4: 0.95s user / 0.47s real (~3x speedup, parallel execution)

Technical Details

The fix aligns Zstd.decompress behavior with:

  • Zstd.compress (already releases GVL via zstd_compress(..., false))
  • StreamingDecompress#decompress (already releases GVL via zstd_stream_decompress(..., false))

This enables decompressing multiple independent compressed data streams in parallel across multiple CPU cores.

Test Plan

  • Verified multi-threaded decompression benchmark shows ~3x speedup with 4 threads
  • Confirmed CPU utilization increases from ~100% to ~300%+ with multiple threads
  • Extension compiles successfully

🤖 Generated with Claude Code

…sion

Changed decode_one_frame to use zstd_stream_decompress with GVL release
instead of calling ZSTD_decompressStream directly. This allows multiple
Ruby threads to decompress independent data in parallel.

Performance improvement with 4 threads:
- Before: ~1.41s (single-threaded, CPU ~100%)
- After: ~0.47s (parallel, ~3x speedup)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@SpringMT
Copy link
Owner Author

SpringMT commented Mar 1, 2026

see #112
close

@SpringMT SpringMT closed this Mar 1, 2026
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