Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Improve IPC performance.
Browse files Browse the repository at this point in the history
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 59be975
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/child_process.js
Expand Up @@ -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();
Expand Down

0 comments on commit 59be975

Please sign in to comment.