Commit ac8e1bf6 authored by Ingvar Stepanyan's avatar Ingvar Stepanyan
Browse files

buffer: improve creation performance.

Improves performance of allocating unsafe buffers, creating buffers from
an existing ArrayBuffer and creating .slice(...) from existing Buffer by
avoiding deoptimizing change of prototype after Uint8Array allocation
in favor of ES6 native subclassing.

This is done through an internal ES6 class that extends Uint8Array and
is used for allocations, but the regular Buffer function is exposed, so
calling Buffer(...) with or without `new` continues to work as usual
and prototype chains are also preserved.

Performance wins for .slice are +120% (2.2x), and, consequently, for
unsafe allocations up to +95% (1.9x) for small buffers, and for safe
allocations (zero-filled) up to +30% (1.3x).

PR-URL: https://github.com/nodejs/node/pull/7349
Ref: https://github.com/nodejs/node/pull/6893


Reviewed-By: default avatarAnna Henningsen <anna@addaleax.net>
Reviewed-By: default avatarСковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: default avatarTrevor Norris <trev.norris@gmail.com>
parent c5442137
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment