Improve IPC performance.

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

Fixes #1864.
This commit is contained in:
Daniel Ennis 2011-10-11 20:54:55 -04:00 committed by Ryan Dahl
parent 73b4b86d29
commit 59be975322

View File

@ -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();