Browse Source

Improve IPC performance.

Reading of JSON data off the buffer, 10-15% performance increase.

Fixes #1864.
v0.7.4-release
Daniel Ennis 13 years ago
committed by Ryan Dahl
parent
commit
59be975322
  1. 9
      lib/child_process.js

9
lib/child_process.js

@ -77,14 +77,15 @@ function setupChannel(target, channel) {
if (pool) {
jsonBuffer += pool.toString('ascii', offset, offset + length);
var i;
while ((i = jsonBuffer.indexOf('\n')) >= 0) {
var json = jsonBuffer.slice(0, i);
var i, start = 0;
while ((i = jsonBuffer.indexOf('\n', start)) >= 0) {
var json = jsonBuffer.slice(start, i);
var message = JSON.parse(json);
jsonBuffer = jsonBuffer.slice(i + 1);
target.emit('message', message, recvHandle);
start = i+1;
}
jsonBuffer = jsonBuffer.slice(start);
} else {
channel.close();

Loading…
Cancel
Save