From b33a47ef473c169be2f11a2ee434f0f89ea1d106 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 23 Aug 2014 00:31:44 +0200 Subject: [PATCH] lib, src: don't make http parser handles weak Weak handles put strain on the garbage collector and the parser handle doesn't need to be weak in the first place. This change should improve GC times on busy servers a little. Reviewed-by: Trevor Norris --- lib/_http_common.js | 3 ++- lib/freelist.js | 2 ++ src/node_http_parser.cc | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/_http_common.js b/lib/_http_common.js index b5995476e5..f3d9d4a2eb 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -200,7 +200,8 @@ function freeParser(parser, req) { parser.socket.parser = null; parser.socket = null; parser.incoming = null; - parsers.free(parser); + if (parsers.free(parser) === false) + parser.close(); parser = null; } if (req) { diff --git a/lib/freelist.js b/lib/freelist.js index 61a3f78f64..588facd25b 100644 --- a/lib/freelist.js +++ b/lib/freelist.js @@ -39,5 +39,7 @@ exports.FreeList.prototype.free = function(obj) { //debug("free " + this.name + " " + this.list.length); if (this.list.length < this.max) { this.list.push(obj); + return true; } + return false; }; diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 04b86097ef..8d9b66ed06 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -169,12 +169,14 @@ class Parser : public BaseObject { : BaseObject(env, wrap), current_buffer_len_(0), current_buffer_data_(NULL) { - MakeWeak(this); + Wrap(object(), this); Init(type); } ~Parser() { + ClearWrap(object()); + persistent().Reset(); } @@ -357,6 +359,13 @@ class Parser : public BaseObject { } + static void Close(const FunctionCallbackInfo& args) { + HandleScope handle_scope(args.GetIsolate()); + Parser* parser = Unwrap(args.Holder()); + delete parser; + } + + void Save() { url_.Save(); status_message_.Save(); @@ -591,6 +600,7 @@ void InitHttpParser(Handle target, #undef V t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "methods"), methods); + NODE_SET_PROTOTYPE_METHOD(t, "close", Parser::Close); NODE_SET_PROTOTYPE_METHOD(t, "execute", Parser::Execute); NODE_SET_PROTOTYPE_METHOD(t, "finish", Parser::Finish); NODE_SET_PROTOTYPE_METHOD(t, "reinitialize", Parser::Reinitialize);