Skip to content

Commit

Permalink
buffer: remove minor perf regression in from()
Browse files Browse the repository at this point in the history
A performance regression was introduced to Buffer.from() between 6.5.0
and 6.6.0. This commit gains back that regression, but does not solve
the actual issue.

From the IRHydra output it seems v8 is doing something every different
in how the functions are evaluated. When passing an array to
Buffer.from() IRHydra shows 31 code blocks in 6.5.0 and 181 code blocks
in 6.6.0. Investigation still needs to be done to determine the root of
this issue.
  • Loading branch information
trevnorris committed Sep 23, 2016
1 parent 0a3ad92 commit e555b5a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ function fromObject(obj) {
}

if (obj) {
if (isArrayBuffer(obj.buffer) || 'length' in obj) {
if (typeof obj.length !== 'number' || obj.length !== obj.length) {
const obj_length = obj.length;
if (isArrayBuffer(obj.buffer) || obj_length) {
if (typeof obj_length !== 'number' || obj_length !== obj_length) {
return new FastBuffer();
}
return fromArrayLike(obj);
Expand Down

0 comments on commit e555b5a

Please sign in to comment.