Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer speedups #1048

Merged
merged 2 commits into from
Mar 5, 2015
Merged

Buffer speedups #1048

merged 2 commits into from
Mar 5, 2015

Commits on Mar 5, 2015

  1. lib: hand-optimize Buffer constructor

    The Buffer constructor is used pervasively throughout io.js, yet it was
    one of the most unwieldy functions in core.  This commit breaks up the
    constructor into several small functions in a way that makes V8 happy.
    
    About 8-10% CPU time was attributed to the constructor function before
    in buffer-heavy benchmarks.  That pretty much drops to zero now because
    V8 can now easily inline it at the call site.  It shortens the running
    time of the following simple benchmark by about 15%:
    
        for (var i = 0; i < 25e6; ++i) new Buffer(1);
    
    And about 8% from this benchmark:
    
        for (var i = 0; i < 1e7; ++i) new Buffer('x', 'ucs2');
    
    PR-URL: nodejs#1048
    Reviewed-By: Trevor Norris <trev.norris@gmail.com>
    bnoordhuis committed Mar 5, 2015
    Configuration menu
    Copy the full SHA
    bbf54a5 View commit details
    Browse the repository at this point in the history
  2. lib: avoid .toLowerCase() call in Buffer#write()

    Avoid a costly String#toLowerCase() call in Buffer#write() in the
    common case, i.e., that the string is already lowercase.  Reduces
    the running time of the following benchmark by about 40%:
    
        for (var b = Buffer(1), i = 0; i < 25e6; ++i) b.write('x', 'ucs2');
    
    PR-URL: nodejs#1048
    Reviewed-By: Trevor Norris <trev.norris@gmail.com>
    bnoordhuis committed Mar 5, 2015
    Configuration menu
    Copy the full SHA
    4ddd640 View commit details
    Browse the repository at this point in the history