diff --git a/lib/utils/staticwriter.js b/lib/utils/staticwriter.js index 46040962..0530c096 100644 --- a/lib/utils/staticwriter.js +++ b/lib/utils/staticwriter.js @@ -10,8 +10,10 @@ const assert = require('assert'); const encoding = require('./encoding'); const digest = require('../crypto/digest'); -const POOL = Buffer.allocUnsafeSlow(100 * 1024); const EMPTY = Buffer.alloc(0); +const POOLSIZE = 100 << 10; + +let POOL = null; /** * Statically allocated buffer writer. @@ -35,11 +37,15 @@ function StaticWriter(size) { */ StaticWriter.pool = function pool(size) { - if (size <= POOL.length) { + if (size <= POOLSIZE) { + if (!POOL) + POOL = Buffer.allocUnsafeSlow(POOLSIZE); + const bw = new StaticWriter(0); bw.data = POOL.slice(0, size); return bw; } + return new StaticWriter(size); };