Skip to content

Commit bf63604

Browse files
addaleaxjuanarbol
authored andcommitted
src: release memory for zstd contexts in Close()
This aligns zstd streams with other compression libraries in this regard, and enables releasing memory early when the stream ends in JS instead of waiting for GC to clean up the wrapper object (which is a problem that is exacerbated in the zstd context because we do not track memory and report memory pressure to V8 yet). PR-URL: #61717 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent d18c010 commit bf63604

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/node_zlib.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ class ZstdContext : public MemoryRetainer {
295295
ZstdContext() = default;
296296

297297
// Streaming-related, should be available for all compression libraries:
298-
void Close();
299298
void SetBuffers(const char* in, uint32_t in_len, char* out, uint32_t out_len);
300299
void SetFlush(int flush);
301300
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
@@ -320,6 +319,7 @@ class ZstdCompressContext final : public ZstdContext {
320319
ZstdCompressContext() = default;
321320

322321
// Streaming-related, should be available for all compression libraries:
322+
void Close();
323323
void DoThreadPoolWork();
324324
CompressionError ResetStream();
325325

@@ -346,6 +346,7 @@ class ZstdDecompressContext final : public ZstdContext {
346346
ZstdDecompressContext() = default;
347347

348348
// Streaming-related, should be available for all compression libraries:
349+
void Close();
349350
void DoThreadPoolWork();
350351
CompressionError ResetStream();
351352

@@ -1490,8 +1491,6 @@ CompressionError BrotliDecoderContext::GetErrorInfo() const {
14901491
}
14911492
}
14921493

1493-
void ZstdContext::Close() {}
1494-
14951494
void ZstdContext::SetBuffers(const char* in,
14961495
uint32_t in_len,
14971496
char* out,
@@ -1535,6 +1534,10 @@ CompressionError ZstdCompressContext::SetParameter(int key, int value) {
15351534
return {};
15361535
}
15371536

1537+
void ZstdCompressContext::Close() {
1538+
cctx_.reset();
1539+
}
1540+
15381541
CompressionError ZstdCompressContext::Init(uint64_t pledged_src_size,
15391542
std::string_view dictionary) {
15401543
pledged_src_size_ = pledged_src_size;
@@ -1587,6 +1590,10 @@ CompressionError ZstdDecompressContext::SetParameter(int key, int value) {
15871590
return {};
15881591
}
15891592

1593+
void ZstdDecompressContext::Close() {
1594+
dctx_.reset();
1595+
}
1596+
15901597
CompressionError ZstdDecompressContext::Init(uint64_t pledged_src_size,
15911598
std::string_view dictionary) {
15921599
dctx_.reset(ZSTD_createDCtx());

0 commit comments

Comments
 (0)