| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3d1d152 commit b572492
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -248,6 +248,7 @@ | |||
| 248 | 248 | ||
| 249 | 249 | [ 'node_shared_zstd=="false"', { | |
| 250 | 250 | 'dependencies': [ 'deps/zstd/zstd.gyp:zstd' ], | |
| 251 | + 'defines': [ 'NODE_BUNDLED_ZSTD' ], | ||
| 251 | 252 | }], | |
| 252 | 253 | ||
| 253 | 254 | [ 'OS=="mac"', { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,10 @@ | |||
| 19 | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | + #ifdef NODE_BUNDLED_ZSTD | ||
| 23 | + #define ZSTD_STATIC_LINKING_ONLY | ||
| 24 | + #endif | ||
| 25 | + | ||
| 22 | 26 | #include "memory_tracker-inl.h" | |
| 23 | 27 | #include "node.h" | |
| 24 | 28 | #include "node_buffer.h" | |
@@ -1549,7 +1553,16 @@ void ZstdCompressContext::Close() { | |||
| 1549 | 1553 | CompressionError ZstdCompressContext::Init(uint64_t pledged_src_size, | |
| 1550 | 1554 | std::string_view dictionary) { | |
| 1551 | 1555 | pledged_src_size_ = pledged_src_size; | |
| 1556 | + #ifdef NODE_BUNDLED_ZSTD | ||
| 1557 | + ZSTD_customMem custom_mem = { | ||
| 1558 | + CompressionStreamMemoryOwner::AllocForBrotli, | ||
| 1559 | + CompressionStreamMemoryOwner::FreeForZlib, | ||
| 1560 | + CompressionStream<ZstdCompressContext>::AllocatorOpaquePointerForContext( | ||
| 1561 | + this)}; | ||
| 1562 | + cctx_.reset(ZSTD_createCCtx_advanced(custom_mem)); | ||
| 1563 | + #else | ||
| 1552 | 1564 | cctx_.reset(ZSTD_createCCtx()); | |
| 1565 | + #endif | ||
| 1553 | 1566 | if (!cctx_) { | |
| 1554 | 1567 | return CompressionError("Could not initialize zstd instance", | |
| 1555 | 1568 | "ERR_ZLIB_INITIALIZATION_FAILED", | |
@@ -1604,7 +1617,16 @@ void ZstdDecompressContext::Close() { | |||
| 1604 | 1617 | ||
| 1605 | 1618 | CompressionError ZstdDecompressContext::Init(uint64_t pledged_src_size, | |
| 1606 | 1619 | std::string_view dictionary) { | |
| 1620 | + #ifdef NODE_BUNDLED_ZSTD | ||
| 1621 | + ZSTD_customMem custom_mem = { | ||
| 1622 | + CompressionStreamMemoryOwner::AllocForBrotli, | ||
| 1623 | + CompressionStreamMemoryOwner::FreeForZlib, | ||
| 1624 | + CompressionStream< | ||
| 1625 | + ZstdDecompressContext>::AllocatorOpaquePointerForContext(this)}; | ||
| 1626 | + dctx_.reset(ZSTD_createDCtx_advanced(custom_mem)); | ||
| 1627 | + #else | ||
| 1607 | 1628 | dctx_.reset(ZSTD_createDCtx()); | |
| 1629 | + #endif | ||
| 1608 | 1630 | if (!dctx_) { | |
| 1609 | 1631 | return CompressionError("Could not initialize zstd instance", | |
| 1610 | 1632 | "ERR_ZLIB_INITIALIZATION_FAILED", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,49 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // This tests heap snapshot integration of zlib stream. | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const { validateByRetainingPath, validateByRetainingPathFromNodes } = require('../common/heap'); | ||
| 7 | + const zlib = require('zlib'); | ||
| 8 | + | ||
| 9 | + // Before zstd stream is created, no ZstdStream should be created. | ||
| 10 | + { | ||
| 11 | + const nodes = validateByRetainingPath('Node / ZstdStream', []); | ||
| 12 | + assert.strictEqual(nodes.length, 0); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + const compress = zlib.createZstdCompress(); | ||
| 16 | + | ||
| 17 | + // After zstd stream is created, a ZstdStream should be created. | ||
| 18 | + { | ||
| 19 | + const streams = validateByRetainingPath('Node / ZstdStream', []); | ||
| 20 | + validateByRetainingPathFromNodes(streams, 'Node / ZstdStream', [ | ||
| 21 | + { node_name: 'ZstdCompress', edge_name: 'native_to_javascript' }, | ||
| 22 | + ]); | ||
| 23 | + const withMemory = validateByRetainingPathFromNodes(streams, 'Node / ZstdStream', [ | ||
| 24 | + { node_name: 'Node / zlib_memory', edge_name: 'zlib_memory' }, | ||
| 25 | + ], true); | ||
| 26 | + if (process.config.variables.node_shared_zstd === true) { | ||
| 27 | + assert.strictEqual(withMemory.length, 0); | ||
| 28 | + } else { | ||
| 29 | + assert.strictEqual(withMemory.length, 1); | ||
| 30 | + // Between 1KB and 1MB (measured value was around ~5kB) | ||
| 31 | + assert.ok(withMemory[0].self_size > 1024); | ||
| 32 | + assert.ok(withMemory[0].self_size < 1024 * 1024); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + // After zstd stream is written, zlib_memory is significantly larger. | ||
| 37 | + compress.write('hello world', common.mustCall(() => { | ||
| 38 | + const streams = validateByRetainingPath('Node / ZstdStream', []); | ||
| 39 | + const withMemory = validateByRetainingPathFromNodes(streams, 'Node / ZstdStream', [ | ||
| 40 | + { node_name: 'Node / zlib_memory', edge_name: 'zlib_memory' }, | ||
| 41 | + ], true); | ||
| 42 | + if (process.config.variables.node_shared_zstd === true) { | ||
| 43 | + assert.strictEqual(withMemory.length, 0); | ||
| 44 | + } else { | ||
| 45 | + assert.strictEqual(withMemory.length, 1); | ||
| 46 | + // More than 1MB | ||
| 47 | + assert.ok(withMemory[0].self_size > 1024 * 1024); | ||
| 48 | + } | ||
| 49 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments