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

napi: improve runtime performance of every napi fun call. #21072

Closed
wants to merge 1 commit into from

Commits on Jun 8, 2018

  1. napi: improve runtime performance of every napi fun call.

    Added a new struct CallbackBundle to eliminate all
    GetInternalField() calls.
    
    The principle is to store all required data inside a C++ struct,
    and then store the pointer in the JavaScript object. Before this
    change, the required data are stored in the JavaScript object in
    3 or 4 seperate pointers. For every napi fun call, 3 of them
    have to be fetched out, which are 3 GetInternalField() calls;
    after this change, the C++ struct will be directly fetched out
    by using v8::External::Value(), which is faster.
    
    Profiling data show that GetInternalField() is slow.
    On an i7-4770K (3.50GHz) box, a C++ V8-binding fun call is 8 ns,
    before this change, napi fun call is 36 ns; after this change,
    napi fun call is 20 ns.
    
    The above data are measured using a modified benchmark in
    'benchmark/misc/function_call'. The modification adds an indicator
    of the average time of a "chatty" napi fun call (max 50M runs).
    This change will speed up chatty case 1.8x (overall), and will cut
    down the delay of napi mechanism to approx. 0.5x.
    
    Background: a simple C++ binding function (e.g. receiving little
    from JS, doing little and returning little to JS) is called
    'chatty' case for JS<-->C++ fun call routine.
    
    This improvement also applies to getter/setter fun calls.
    kenny-y committed Jun 8, 2018
    Configuration menu
    Copy the full SHA
    cd38061 View commit details
    Browse the repository at this point in the history