child_process: introduce binary protocol to optimizing performance#393
child_process: introduce binary protocol to optimizing performance#393
Conversation
yorkie
left a comment
There was a problem hiding this comment.
Nice works, there are some suggestions to leave, please fix those @lolBig.
| return offset + 4; | ||
| }; | ||
|
|
||
| Buffer.prototype.writeInt32BE = function(value, offset, noAssert) { |
There was a problem hiding this comment.
Should add some comments like:
// buff.readUInt8(offset[,noAssert])
// [1] buff.readUInt8(offset)
// [2] buff.readUInt8(offset, noAssert)
| (this._builtin.readUInt8(offset + 3) << 24); | ||
| }; | ||
|
|
||
| Buffer.prototype.readInt32BE = function(offset, noAssert) { |
There was a problem hiding this comment.
Ditto, BTW you need to update our Buffer docs, too.
src/js/child_process.js
Outdated
| var SIGNAL_NO = constants.os.signals; | ||
| var INTERNAL_IPC_HEADER_LENGTH_SIZE = constants.INTERNAL_IPC_HEADER_LENGTH_SIZE; | ||
| var INTERNAL_IPC_HEADER_SIZE = constants.INTERNAL_IPC_HEADER_SIZE; | ||
| var INTERNAL_IPC_PAYLOAD_MAX_SIZE = constants.INTERNAL_IPC_PAYLOAD_MAX_SIZE; |
There was a problem hiding this comment.
Define all above constants only in child_process.js if those won't be used by others?
| var dataSize = channel.pendingBuffer.readInt32BE(headerOffset); | ||
| var typeOffset = headerOffset + INTERNAL_IPC_HEADER_LENGTH_SIZE; | ||
| var dataType = channel.pendingBuffer.readInt32BE(typeOffset); | ||
| var dataBegin = headerOffset + INTERNAL_IPC_HEADER_SIZE; |
There was a problem hiding this comment.
Could we have an abstracted IpcMessage class like the following:
while (bufLength - headerOffset >= INTERNAL_IPC_HEADER_SIZE) {
var message = new IpcMessage(channel);
// ...
if (message.isObject()) { }
}| message = message.toString(); | ||
| } else { | ||
| throw new Error('ERR_IPC_MESSAGE_TYPE_INVALID'); | ||
| } |
There was a problem hiding this comment.
Ditto, we could add a method serialize() on IpcMessage to make it read easier :)
src/modules/iotjs_module_pipe.c
Outdated
| write_data->data = malloc(sizeof(char) * size); | ||
| memcpy(write_data->data, data, size); | ||
| write_data->callback = callback; | ||
| uv_write_t* write_req = IOTJS_ALLOC(uv_write_t); |
There was a problem hiding this comment.
How about make iotjs_write_data to be iotjs_write_wrap like the following:
typedef struct iotjs_pipe_write_data {
char* data;
uv_write_t req;
jerry_value_t callback;
} iotjs_pipe_write_data;So we could only need to malloc once :)
src/modules/iotjs_module_pipe.c
Outdated
| iotjs_jval_set_method(proto, "listen", PipeListen); | ||
| // iotjs_jval_set_method(proto, "connect", PipeConnect); | ||
| iotjs_jval_set_method(proto, "readStart", PipeReadStart); | ||
| iotjs_jval_set_method(proto, "write", Write); |
There was a problem hiding this comment.
It's better to use MAGIC_STRING :)
test/run_pass/test_process_send.js
Outdated
| var assert = require('assert'); | ||
| // json length is close to 19KB | ||
| var data = require('./test_process_send.json'); | ||
| var dataStr = JSON.stringify(data) |
test/run_pass/test_process_send.js
Outdated
| // json length is close to 19KB | ||
| var data = require('./test_process_send.json'); | ||
| var dataStr = JSON.stringify(data) | ||
| var name = process.send ? 'child' : 'parent' |
test/run_pass/test_process_send.js
Outdated
| if (times <= 0) { | ||
| clearInterval(timer); | ||
| } | ||
| }, 500) No newline at end of file |
There was a problem hiding this comment.
This test is more like as a benchmark script, we actually need the unit tests, could you please add an case that just acquire the API works and move this to benchmark?
|
By the way, @lolBig you forget to add your test into "testsets.json" :) |
src/iotjs_magic_strings.h
Outdated
| #define IOTJS_MAGIC_STRING_WRITESYNC "writeSync" | ||
| #define IOTJS_MAGIC_STRING_WRITEUINT8 "writeUInt8" | ||
| #define IOTJS_MAGIC_STRING_WRITE "write" | ||
| #define IOTJS_MAGIC_STRING_WRITE_UTF8_STRING "writeUtf8String" |
There was a problem hiding this comment.
IOTJS_MAGIC_STRING_WRITEUTF8STRING
src/modules/iotjs_module_pipe.c
Outdated
|
|
||
| static void iotjs_pipe_after_write(uv_write_t* req, int status) { | ||
| jerry_value_t callback = (jerry_value_t)(uintptr_t)req->data; | ||
| iotjs_write_wrap* write_data = (iotjs_write_wrap*)req->data; |
There was a problem hiding this comment.
Use the writer_wrap instead of write_data
* master: build: use CMAKE_INSTALL_PREFIX instead of custom install command (#391) child_process: introduce binary protocol to optimizing performance (#393) iotjs: cache parsed dump table for error.stack at runtime (#392) jerry: merge a59cf4f from upstream to optimize the function call (#381) promise: optimize the performance on .then and static resolve (#385) jerry: set prototype/constructor for external functions (#386) process: add shebang parser supports (#379) napi: fix complete callback segv/ticks on async-work (#380) jerry: pass regression-test-issue-2105 for heapdump (#382) tls, mqtts: fix connection not be actively disconnected (#375) websocket: fix the crash due to http exception (#376) process: add signal events support (#372)
No description provided.