From aceb1987ed64b142595e7b74c88d6aff264e0144 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 29 May 2009 17:05:03 +0200 Subject: [PATCH] Remove complex string appending in http's send() method. That seems to churn the garbage collector like mad. Before: http://s3.amazonaws.com/four.livejournal/20090529/timeseries6.png After: http://s3.amazonaws.com/four.livejournal/20090529/timeseries11.png Got a nice tight side profile for this benchmark now: http://s3.amazonaws.com/four.livejournal/20090529/hist10.png --- src/http.js | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/http.js b/src/http.js index fad9535..c379812 100644 --- a/src/http.js +++ b/src/http.js @@ -102,45 +102,12 @@ function toRaw(string) { return a; } -// The send method appends data onto the output array. The deal is, -// the data is either an array of integer, representing binary or it -// is a string in which case it's UTF8 encoded. -// Two things to be considered: -// - we should be able to send mixed encodings. -// - we don't want to call connection.send("smallstring") because that -// is wasteful. *I think* its rather faster to concat inside of JS -// Thus I attempt to concat as much as possible. -// -// XXX this function is extremely ugly function send (output, data, encoding) { if (data.constructor === String) encoding = encoding || "ascii"; else encoding = "raw"; - if (output.length == 0) { - output.push([data, encoding]); - return; - } - - var li = output.length-1; - var last_encoding = output[li][1]; - - if (data.constructor === String) { - if ( last_encoding === encoding - || (last_encoding === "utf8" && encoding === "ascii") - ) - { - output[li][0] += data; - return; - } - } - - if (data.constructor === Array && last_encoding === encoding) { - output[li][0] = output[li][0].concat(data); - return; - } - output.push([data, encoding]); }; -- 2.7.4