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

Reduce copying for large payloads #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/rapid-client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class RuntimeApiNextPromiseWorker : public Napi::AsyncWorker {
return;
}

// TODO: See if json parsing works on V8:Buffer objects, which might be a way to reduce copying large payloads
response = outcome.get_result();
response = std::move(outcome).get_result();
}

Napi::Value Promise() {
Expand All @@ -51,7 +50,7 @@ class RuntimeApiNextPromiseWorker : public Napi::AsyncWorker {

void OnOK() override {
Napi::Env env = Env();
auto response_data = Napi::String::New(env, response.payload.c_str());
auto response_data = Napi::String::New(env, response.payload);

// TODO: The current javascript code (InvokeContext.js) to handle the header values itself.
// These type conversions might be replaced by returning the final context object.
Expand All @@ -65,22 +64,22 @@ class RuntimeApiNextPromiseWorker : public Napi::AsyncWorker {
));
headers.Set(
Napi::String::New(env, "lambda-runtime-aws-request-id"),
Napi::String::New(env, response.request_id.c_str()));
Napi::String::New(env, response.request_id));
headers.Set(
Napi::String::New(env, "lambda-runtime-trace-id"),
Napi::String::New(env, response.xray_trace_id.c_str()));
Napi::String::New(env, response.xray_trace_id));
headers.Set(
Napi::String::New(env, "lambda-runtime-invoked-function-arn"),
Napi::String::New(env, response.function_arn.c_str()));
if (response.client_context != "") {
Napi::String::New(env, response.function_arn));
if (!response.client_context.empty()) {
headers.Set(
Napi::String::New(env, "lambda-runtime-client-context"),
Napi::String::New(env, response.client_context.c_str()));
Napi::String::New(env, response.client_context));
}
if (response.cognito_identity != "") {
if (!response.cognito_identity.empty()) {
headers.Set(
Napi::String::New(env, "lambda-runtime-cognito-identity"),
Napi::String::New(env, response.cognito_identity.c_str()));
Napi::String::New(env, response.cognito_identity));
}

auto ret = Napi::Object::New(env);
Expand Down
Loading