Skip to content

Commit b33a47e

Browse files
bnoordhuistrevnorris
authored andcommitted
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 <trev.norris@gmail.com>
1 parent 1e99486 commit b33a47e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/_http_common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ function freeParser(parser, req) {
200200
parser.socket.parser = null;
201201
parser.socket = null;
202202
parser.incoming = null;
203-
parsers.free(parser);
203+
if (parsers.free(parser) === false)
204+
parser.close();
204205
parser = null;
205206
}
206207
if (req) {

lib/freelist.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ exports.FreeList.prototype.free = function(obj) {
3939
//debug("free " + this.name + " " + this.list.length);
4040
if (this.list.length < this.max) {
4141
this.list.push(obj);
42+
return true;
4243
}
44+
return false;
4345
};

src/node_http_parser.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ class Parser : public BaseObject {
169169
: BaseObject(env, wrap),
170170
current_buffer_len_(0),
171171
current_buffer_data_(NULL) {
172-
MakeWeak<Parser>(this);
172+
Wrap(object(), this);
173173
Init(type);
174174
}
175175

176176

177177
~Parser() {
178+
ClearWrap(object());
179+
persistent().Reset();
178180
}
179181

180182

@@ -357,6 +359,13 @@ class Parser : public BaseObject {
357359
}
358360

359361

362+
static void Close(const FunctionCallbackInfo<Value>& args) {
363+
HandleScope handle_scope(args.GetIsolate());
364+
Parser* parser = Unwrap<Parser>(args.Holder());
365+
delete parser;
366+
}
367+
368+
360369
void Save() {
361370
url_.Save();
362371
status_message_.Save();
@@ -591,6 +600,7 @@ void InitHttpParser(Handle<Object> target,
591600
#undef V
592601
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "methods"), methods);
593602

603+
NODE_SET_PROTOTYPE_METHOD(t, "close", Parser::Close);
594604
NODE_SET_PROTOTYPE_METHOD(t, "execute", Parser::Execute);
595605
NODE_SET_PROTOTYPE_METHOD(t, "finish", Parser::Finish);
596606
NODE_SET_PROTOTYPE_METHOD(t, "reinitialize", Parser::Reinitialize);

0 commit comments

Comments
 (0)