diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-02-23 18:53:54 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-15 14:53:22 +0300 |
commit | d93c48bf61d6b74bc080da8568df6f2eac44f275 (patch) | |
tree | 2c3001c36c355ad67e58753e40179d9d677fee12 /src/stream_base-inl.h | |
parent | 12b9ec09b0807a0b362986c80d3c4b9a644c611e (diff) |
src: use ObjectTemplate for creating stream req objs
This allows V8 to avoid preparing a execution context
for the constructor, to give a (kinda) small but noticeable
perf gain.
Benchmarks (only this commit):
$ ./node benchmark/compare.js --new ./node --old ./node-master --filter net-c2s.js --set len=10 --set type=asc --runs 360 net | Rscript benchmark/compare.R
[01:15:27|% 100| 1/1 files | 720/720 runs | 1/1 configs]: Done
confidence improvement accuracy (*) (**) (***)
net/net-c2s.js dur=5 type='asc' len=10 *** 0.69 % ±0.31% ±0.41% ±0.53%
PR-URL: https://github.com/nodejs/node/pull/18936
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 7523b3a5453..f4c228d7c59 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -164,8 +164,9 @@ inline int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) { if (req_wrap_obj.IsEmpty()) { req_wrap_obj = - env->shutdown_wrap_constructor_function() + env->shutdown_wrap_template() ->NewInstance(env->context()).ToLocalChecked(); + StreamReq::ResetObject(req_wrap_obj); } AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); @@ -203,8 +204,9 @@ inline StreamWriteResult StreamBase::Write( if (req_wrap_obj.IsEmpty()) { req_wrap_obj = - env->write_wrap_constructor_function() + env->write_wrap_template() ->NewInstance(env->context()).ToLocalChecked(); + StreamReq::ResetObject(req_wrap_obj); } AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); @@ -427,6 +429,15 @@ inline void StreamReq::Done(int status, const char* error_str) { OnDone(status); } +inline void StreamReq::ResetObject(v8::Local<v8::Object> obj) { +#ifdef DEBUG + CHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField); +#endif + ClearWrap(obj); + obj->SetAlignedPointerInInternalField(StreamReq::kStreamReqField, nullptr); +} + + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |