Skip to content

Enhancement: pass data created in threadpool back to main JS thread in zero-copy way #69

@springmeyer

Description

@springmeyer

The #67 talks about a critical optimization when passing data into the threadpool (to do work on it). The corresponding optimization that is equally important is that large data created in the threadpool needs to be efficiently passed back across the boundary from C++ to JS.

Otherwise if the data is large then this hurts performance in the After callback (called HandleOkCallback when using Nan::AsyncWorker), which runs on the main event loop. In particular, large copies at this point can trigger expensive allocation and further slow down the main event loop.

refs this code:

void HandleOKCallback() override
{
Nan::HandleScope scope;
const auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {
Nan::Null(), Nan::New<v8::String>(result_).ToLocalChecked()};
callback->Call(argc, argv);
}
.

Proposal

Modify node-cpp-skel to return a node::Buffer from the threadpool using node::Buffer::New.

We'll need to modify the example code to make this logical: we'll need to invent a scenario where a node::Buffer would be appropriate. A good example of this is when passing gzip compressed data back from the threadpool.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions