Skip to content

Commit 3f9ed69

Browse files
addaleaxmarco-ippolito
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 4600ae7 commit 3f9ed69

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

@@ -1494,8 +1495,6 @@ CompressionError BrotliDecoderContext::GetErrorInfo() const {
14941495
}
14951496
}
14961497

1497-
void ZstdContext::Close() {}
1498-
14991498
void ZstdContext::SetBuffers(const char* in,
15001499
uint32_t in_len,
15011500
char* out,
@@ -1539,6 +1538,10 @@ CompressionError ZstdCompressContext::SetParameter(int key, int value) {
15391538
return {};
15401539
}
15411540

1541+
void ZstdCompressContext::Close() {
1542+
cctx_.reset();
1543+
}
1544+
15421545
CompressionError ZstdCompressContext::Init(uint64_t pledged_src_size,
15431546
std::string_view dictionary) {
15441547
pledged_src_size_ = pledged_src_size;
@@ -1591,6 +1594,10 @@ CompressionError ZstdDecompressContext::SetParameter(int key, int value) {
15911594
return {};
15921595
}
15931596

1597+
void ZstdDecompressContext::Close() {
1598+
dctx_.reset();
1599+
}
1600+
15941601
CompressionError ZstdDecompressContext::Init(uint64_t pledged_src_size,
15951602
std::string_view dictionary) {
15961603
dctx_.reset(ZSTD_createDCtx());

0 commit comments

Comments
 (0)