From 585f5a7d1ade0f0fea5ecaecad95935fb09edf88 Mon Sep 17 00:00:00 2001 From: Spring_MT Date: Mon, 2 Mar 2026 00:00:03 +0900 Subject: [PATCH] Release GVL during Zstd.decompress to enable multi-threaded decompression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- ext/zstdruby/zstdruby.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/zstdruby/zstdruby.c b/ext/zstdruby/zstdruby.c index 1649fe5..425a809 100644 --- a/ext/zstdruby/zstdruby.c +++ b/ext/zstdruby/zstdruby.c @@ -51,7 +51,7 @@ static VALUE decode_one_frame(ZSTD_DCtx* dctx, const unsigned char* src, size_t for (;;) { ZSTD_outBuffer o = (ZSTD_outBuffer){ buf, cap, 0 }; - size_t ret = ZSTD_decompressStream(dctx, &o, &in); + size_t ret = zstd_stream_decompress(dctx, &o, &in, false); if (ZSTD_isError(ret)) { xfree(buf); rb_raise(rb_eRuntimeError, "ZSTD_decompressStream failed: %s", ZSTD_getErrorName(ret));