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

Investigate why running the wasm blob in Postject is slow #85

Closed
RaisinTen opened this issue May 4, 2023 · 0 comments · Fixed by #86
Closed

Investigate why running the wasm blob in Postject is slow #85

RaisinTen opened this issue May 4, 2023 · 0 comments · Fixed by #86

Comments

@RaisinTen
Copy link
Contributor

RaisinTen commented May 4, 2023

See the discussion in nodejs/node#47741.


Measurements of injecting a 4KB resource into a Mach-O binary on an x86_64 macOS with Node.js v20.1.0:

TLDR -

std::vector<uint8_t> vec_from_val(const emscripten::val& value) {
// TODO(dsanders11) - vecFromJSArray incurs a copy, so memory usage is higher
// than it needs to be. Explore ways to access the memory
// directly and avoid the copy.
return emscripten::vecFromJSArray<uint8_t>(value);
}
is where the bottleneck is.

Replacing the emscripten::vecFromJSArray<uint8_t>(value) call at

return emscripten::vecFromJSArray<uint8_t>(value);
with a call to emscripten::vecFromJSArray<uint8_t>(value) reduces the time consumption from ~30s to ~6s.

RaisinTen added a commit to RaisinTen/postject that referenced this issue May 15, 2023
This change replaces the [`vecFromJSArray()`](https://emscripten.org/docs/api_reference/val.h.html?highlight=vecfromjsarray#_CPPv4N10emscripten10emscripten3val14vecFromJSArrayERK3val)
call in `vec_from_val()` with a
call to [`convertJSArrayToNumberVector()`](https://emscripten.org/docs/api_reference/val.h.html?highlight=convertjsarraytonumbervector#_CPPv4N10emscripten10emscripten3val28convertJSArrayToNumberVectorERK3val),
which reduces the time consumption of Postject from ~30s to ~6s on a
Mach-O Node.js binary when run on my x86_64 macOS.

Fixes: nodejs#85
Refs: emscripten-core/emscripten#11119
Signed-off-by: Darshan Sen <raisinten@gmail.com>
RaisinTen added a commit that referenced this issue May 18, 2023
* feat: make postject faster

This change replaces the [`vecFromJSArray()`](https://emscripten.org/docs/api_reference/val.h.html?highlight=vecfromjsarray#_CPPv4N10emscripten10emscripten3val14vecFromJSArrayERK3val)
call in `vec_from_val()` with a
call to [`convertJSArrayToNumberVector()`](https://emscripten.org/docs/api_reference/val.h.html?highlight=convertjsarraytonumbervector#_CPPv4N10emscripten10emscripten3val28convertJSArrayToNumberVectorERK3val),
which reduces the time consumption of Postject from ~30s to ~6s on a
Mach-O Node.js binary when run on my x86_64 macOS.

Fixes: #85
Refs: emscripten-core/emscripten#11119
Signed-off-by: Darshan Sen <raisinten@gmail.com>

* fix: increase timeout to pass tests on Windows

Refs: https://app.circleci.com/pipelines/github/RaisinTen/postject/7/workflows/4bfbf11d-4796-459d-a339-a28098670f37/jobs/77/tests
Signed-off-by: Darshan Sen <raisinten@gmail.com>

---------

Signed-off-by: Darshan Sen <raisinten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant