From def91a1ab2c7daf5ae903e7ca8d75808ed6f04d0 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 5 Apr 2019 10:14:01 -0700 Subject: [PATCH] blockstore: use `alloc` for block buffer allocation for now There is potential for around a 10% to 23% increase to the performance of block reads by using `allocUnsafe`, however there is already around a 3 to 6 times increase to the performance, and this optimization can be added later. While it's safe to use `allocUnsafe` as the number of bytes read is checked to be the same size as the buffer allocation, there is a potential for test cases to introduce _other_ behavior for `fs.read` that may not have the same behavior, though this isn't currently the case. --- lib/blockstore/file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blockstore/file.js b/lib/blockstore/file.js index b4ec86204..027333363 100644 --- a/lib/blockstore/file.js +++ b/lib/blockstore/file.js @@ -482,7 +482,7 @@ class FileBlockStore extends AbstractBlockStore { if (offset + length > blockrecord.length) throw new Error('Out-of-bounds read.'); - const data = Buffer.allocUnsafe(length); + const data = Buffer.alloc(length); const fd = await fs.open(filepath, 'r'); let bytes = 0;