Closed RaisinTen closed 1 year ago
See the discussion in https://github.com/nodejs/node/issues/47741.
Measurements of injecting a 4KB resource into a Mach-O binary on an x86_64 macOS with Node.js v20.1.0:
x86_64
Loading the Emscripten-generated script (https://github.com/emscripten-core/emscripten/blob/90d76db21200d42f5536bc3a01a22303e398d8b4/src/shell.js, https://github.com/emscripten-core/emscripten/blob/90d76db21200d42f5536bc3a01a22303e398d8b4/src/preamble.js, etc.): https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/api.js#L25 takes ~50ms.
Getting the executable format - https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/api.js#L32 takes ~14ms for a 60KB hello-world executable. For the Node.js binary, which is 94MB, it takes ~13s.
Injecting the resource - https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/api.js#L53-L59 takes ~35ms for a 60KB hello-world executable. For the Node.js binary, which is 94MB, it takes ~20s.
vec_from_val
parse
TLDR - https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/postject.cpp#L16-L21 is where the bottleneck is.
Replacing the emscripten::vecFromJSArray<uint8_t>(value) call at https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/postject.cpp#L20 with a call to emscripten::vecFromJSArray<uint8_t>(value) reduces the time consumption from ~30s to ~6s.
emscripten::vecFromJSArray<uint8_t>(value)
See the discussion in https://github.com/nodejs/node/issues/47741.
Measurements of injecting a 4KB resource into a Mach-O binary on an
x86_64
macOS with Node.js v20.1.0:Loading the Emscripten-generated script (https://github.com/emscripten-core/emscripten/blob/90d76db21200d42f5536bc3a01a22303e398d8b4/src/shell.js, https://github.com/emscripten-core/emscripten/blob/90d76db21200d42f5536bc3a01a22303e398d8b4/src/preamble.js, etc.): https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/api.js#L25 takes ~50ms.
Getting the executable format - https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/api.js#L32 takes ~14ms for a 60KB hello-world executable. For the Node.js binary, which is 94MB, it takes ~13s.
Injecting the resource - https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/api.js#L53-L59 takes ~35ms for a 60KB hello-world executable. For the Node.js binary, which is 94MB, it takes ~20s.
vec_from_val
call in https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/postject.cpp#L96, is one of the bottlenecks here as it takes ~12s.parse
call in https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/postject.cpp#L96 takes ~3s.TLDR - https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/postject.cpp#L16-L21 is where the bottleneck is.
Replacing the
emscripten::vecFromJSArray<uint8_t>(value)
call at https://github.com/nodejs/postject/blob/24818680fef14b298e251dd0645fb290a5e8e280/src/postject.cpp#L20 with a call toemscripten::vecFromJSArray<uint8_t>(value)
reduces the time consumption from ~30s to ~6s.