Browse Source

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
v0.7.4-release
Ryan 16 years ago
parent
commit
aceb1987ed
  1. 33
      src/http.js

33
src/http.js

@ -102,45 +102,12 @@ function toRaw(string) {
return a; 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) { function send (output, data, encoding) {
if (data.constructor === String) if (data.constructor === String)
encoding = encoding || "ascii"; encoding = encoding || "ascii";
else else
encoding = "raw"; 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]); output.push([data, encoding]);
}; };

Loading…
Cancel
Save