Skip to content

Commit

Permalink
blockstore: use alloc for block buffer allocation for now
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
braydonf committed Apr 5, 2019
1 parent 034621b commit def91a1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blockstore/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit def91a1

Please sign in to comment.