summaryrefslogtreecommitdiff
path: root/lib/http.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-03-14 07:48:18 -0700
committerisaacs <i@izs.me>2013-03-14 08:04:59 -0700
commitd62cf59dc152f8df6954ee7ffe9381fc9b524e32 (patch)
treed1bd374e9882cde58c4a78a05def9656830d15c3 /lib/http.js
parentca5022b8f10c95d834678108adcd12f1c907016e (diff)
downloadandroid-node-v8-d62cf59dc152f8df6954ee7ffe9381fc9b524e32.tar.gz
android-node-v8-d62cf59dc152f8df6954ee7ffe9381fc9b524e32.tar.bz2
android-node-v8-d62cf59dc152f8df6954ee7ffe9381fc9b524e32.zip
http: Don't hot-path end() for large buffers
The benefits of the hot-path optimization below start to fall off when the buffer size gets up near 128KB, because the cost of the copy is more than the cost of the extra write() call. Switch to the write/end method at that point. Heuristics and magic numbers are awful, but slow http responses are worse. Fix #4975
Diffstat (limited to 'lib/http.js')
-rw-r--r--lib/http.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/http.js b/lib/http.js
index 2bceaa0152..dacedd4477 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -855,6 +855,14 @@ OutgoingMessage.prototype.end = function(data, encoding) {
this.connection.writable &&
this.connection._httpMessage === this;
+ // The benefits of the hot-path optimization below start to fall
+ // off when the buffer size gets up near 128KB, because the cost
+ // of the copy is more than the cost of the extra write() call.
+ // Switch to the write/end method at that point. Heuristics and
+ // magic numbers are awful, but slow http responses are worse.
+ if (hot && Buffer.isBuffer(data) && data.length > 120 * 1024)
+ hot = false;
+
if (hot) {
// Hot path. They're doing
// res.writeHead();