Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
zlib: pass object size hint to V8
Browse files Browse the repository at this point in the history
Inform V8 that the zlib context object is tied to a large off-heap buffer.

This makes the GC run more often (in theory) and improves the accuracy of
--trace_external_memory.
  • Loading branch information
bnoordhuis committed Oct 30, 2012
1 parent 570e4be commit a93424d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/node_zlib.cc
Expand Up @@ -74,9 +74,11 @@ class ZCtx : public ObjectWrap {

if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) {
(void)deflateEnd(&strm_);
V8::AdjustAmountOfExternalAllocatedMemory(-kDeflateContextSize);
} else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW ||
mode_ == UNZIP) {
(void)inflateEnd(&strm_);
V8::AdjustAmountOfExternalAllocatedMemory(-kInflateContextSize);
}
mode_ = NONE;

Expand Down Expand Up @@ -366,12 +368,14 @@ class ZCtx : public ObjectWrap {
ctx->windowBits_,
ctx->memLevel_,
ctx->strategy_);
V8::AdjustAmountOfExternalAllocatedMemory(kDeflateContextSize);
break;
case INFLATE:
case GUNZIP:
case INFLATERAW:
case UNZIP:
ctx->err_ = inflateInit2(&ctx->strm_, ctx->windowBits_);
V8::AdjustAmountOfExternalAllocatedMemory(kInflateContextSize);
break;
default:
assert(0 && "wtf?");
Expand Down Expand Up @@ -432,6 +436,8 @@ class ZCtx : public ObjectWrap {
}

private:
static const int kDeflateContextSize = 16384; // approximate
static const int kInflateContextSize = 10240; // approximate

bool init_done_;

Expand Down

0 comments on commit a93424d

Please sign in to comment.