summaryrefslogtreecommitdiff
path: root/src/env.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-12-19 15:08:18 +0100
committerAnna Henningsen <anna@addaleax.net>2017-12-27 19:48:07 +0100
commit83e5215a4e8438a43b9f0002b7a43e2fd2dd37a4 (patch)
tree3a0be3dda02df06814d9ec9b73a22c1afa4b0ddc /src/env.cc
parentdf30fd586d123fc189887fc0f9c7f27808374c2e (diff)
downloadandroid-node-v8-83e5215a4e8438a43b9f0002b7a43e2fd2dd37a4.tar.gz
android-node-v8-83e5215a4e8438a43b9f0002b7a43e2fd2dd37a4.tar.bz2
android-node-v8-83e5215a4e8438a43b9f0002b7a43e2fd2dd37a4.zip
async_hooks: use typed array stack as fast path
- Communicate the current async stack length through a typed array field rather than a native binding method - Add a new fixed-size `async_ids_fast_stack` typed array that contains the async ID stack up to a fixed limit. This increases performance noticeably, since most of the time the async ID stack will not be more than a handful of levels deep. - Make the JS `pushAsyncIds()` and `popAsyncIds()` functions do the same thing as the native ones if the fast path is applicable. Benchmarks: $ ./node benchmark/compare.js --new ./node --old ./node-master --runs 10 --filter next-tick process | Rscript benchmark/compare.R [00:03:25|% 100| 6/6 files | 20/20 runs | 1/1 configs]: Done improvement confidence p.value process/next-tick-breadth-args.js millions=4 19.72 % *** 3.013913e-06 process/next-tick-breadth.js millions=4 27.33 % *** 5.847983e-11 process/next-tick-depth-args.js millions=12 40.08 % *** 1.237127e-13 process/next-tick-depth.js millions=12 77.27 % *** 1.413290e-11 process/next-tick-exec-args.js millions=5 13.58 % *** 1.245180e-07 process/next-tick-exec.js millions=5 16.80 % *** 2.961386e-07 PR-URL: https://github.com/nodejs/node/pull/17780 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc
index c3f42302ae..eb8cad15ed 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -403,4 +403,21 @@ void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object,
syscall, message, path, dest);
}
+
+void Environment::AsyncHooks::grow_async_ids_stack() {
+ const uint32_t old_capacity = async_ids_stack_.Length() / 2;
+ const uint32_t new_capacity = old_capacity * 1.5;
+ AliasedBuffer<double, v8::Float64Array> new_buffer(
+ env()->isolate(), new_capacity * 2);
+
+ for (uint32_t i = 0; i < old_capacity * 2; ++i)
+ new_buffer[i] = async_ids_stack_[i];
+ async_ids_stack_ = std::move(new_buffer);
+
+ env()->async_hooks_binding()->Set(
+ env()->context(),
+ env()->async_ids_stack_string(),
+ async_ids_stack_.GetJSArray()).FromJust();
+}
+
} // namespace node