Skip to content

Commit

Permalink
lib, src: don't make http parser handles weak
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bnoordhuis authored and trevnorris committed Sep 5, 2014
1 parent 1e99486 commit b33a47e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/freelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
12 changes: 11 additions & 1 deletion src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ class Parser : public BaseObject {
: BaseObject(env, wrap),
current_buffer_len_(0),
current_buffer_data_(NULL) {
MakeWeak<Parser>(this);
Wrap(object(), this);
Init(type);
}


~Parser() {
ClearWrap(object());
persistent().Reset();
}


Expand Down Expand Up @@ -357,6 +359,13 @@ class Parser : public BaseObject {
}


static void Close(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Parser* parser = Unwrap<Parser>(args.Holder());
delete parser;
}


void Save() {
url_.Save();
status_message_.Save();
Expand Down Expand Up @@ -591,6 +600,7 @@ void InitHttpParser(Handle<Object> 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);
Expand Down

0 comments on commit b33a47e

Please sign in to comment.