Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Improve IPC performance.

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

Fixes #1864.
  • Loading branch information...
aikar authored and ry committed Oct 12, 2011
1 parent 73b4b86 commit 59be97532269a208f0121060772528690a63677b
Showing with 5 additions and 4 deletions.
  1. +5 −4 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();

0 comments on commit 59be975

Please sign in to comment.
You can’t perform that action at this time.