child_process: serialize advanced IPC messages natively · nodejs/node@04c04c8 · GitHub
Skip to content

Commit 04c04c8

Browse files
anonrigaduh95
authored andcommitted
child_process: serialize advanced IPC messages natively
The `advanced` IPC serialization codec was implemented in JavaScript (ChildProcessSerializer / ChildProcessDeserializer in lib/internal/child_process/serialization.js). It allocated a wrapper serializer/deserializer per message and crossed the JS/C++ boundary several times for every message (writeHeader, writeValue, releaseBuffer, readHeader, readValue and friends). Move the codec into a native `ipc_serdes` binding that drives the V8 ValueSerializer/ValueDeserializer with a C++ delegate. The wire format is preserved byte-for-byte: a big-endian uint32 length prefix followed by the V8 payload, with ArrayBufferViews tagged as host objects so that Node Buffers round-trip as Buffers rather than plain Uint8Arrays. The JSON codec is left unchanged. A cctest (test/cctest/test_node_ipc_serdes.cc) exercises the binding directly, covering round-trips of primitives, objects, typed arrays and Buffers (including the Buffer-vs-Uint8Array distinction) and asserting the big-endian length-prefix framing. Round-trip throughput (benchmark/child_process/child-process-ipc-roundtrip): payload before after change 64 B ~300k/s ~800k/s +166% 1 KiB ~272k/s ~616k/s +126% 16 KiB ~91k/s ~120k/s +32% 64 KiB ~30k/s ~35k/s +16% The gain is largest for small messages, where per-message JavaScript overhead dominated, and tapers for large messages, where the actual serialization (already native) dominates. Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> PR-URL: #63933 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 97aafe2 commit 04c04c8

9 files changed

Lines changed: 739 additions & 50 deletions

File tree

lib/internal/child_process/serialization.js

Lines changed: 8 additions & 50 deletions

node.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
'src/node_http_parser.cc',
136136
'src/node_http2.cc',
137137
'src/node_i18n.cc',
138+
'src/node_ipc_serdes.cc',
138139
'src/node_locks.cc',
139140
'src/node_main_instance.cc',
140141
'src/node_messaging.cc',

src/node_binding.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
V(http_parser) \
6060
V(inspector) \
6161
V(internal_only_v8) \
62+
V(ipc_serdes) \
6263
V(js_stream) \
6364
V(js_udp_wrap) \
6465
V(locks) \

src/node_external_reference.h

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)