aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnatoli Papirovski <anatoli.papirovski@postmates.com>2019-03-31 12:42:26 -0700
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-04-05 05:37:11 +0200
commit2c49e8b537a5fba07568c2363ba6a594caa74c17 (patch)
tree9a2bdf0b3042ed3a165cde8ff3ff2f970424327d /lib
parentd3d4e10107a594a758baf2cd5e2c1258671e58c5 (diff)
downloadandroid-node-v8-2c49e8b537a5fba07568c2363ba6a594caa74c17.tar.gz
android-node-v8-2c49e8b537a5fba07568c2363ba6a594caa74c17.tar.bz2
android-node-v8-2c49e8b537a5fba07568c2363ba6a594caa74c17.zip
lib: make queueMicrotask faster
No longer create an additional scope within queueMicrotask in order to improve performance. PR-URL: https://github.com/nodejs/node/pull/27032 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/process/task_queues.js36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js
index 65ac093802..5f5ca5a008 100644
--- a/lib/internal/process/task_queues.js
+++ b/lib/internal/process/task_queues.js
@@ -37,6 +37,8 @@ const {
} = require('internal/errors').codes;
const FixedQueue = require('internal/fixed_queue');
+const FunctionBind = Function.call.bind(Function.prototype.bind);
+
// *Must* match Environment::TickInfo::Fields in src/env.h.
const kHasTickScheduled = 0;
@@ -149,28 +151,32 @@ function createMicrotaskResource() {
});
}
+function runMicrotask() {
+ this.runInAsyncScope(() => {
+ const callback = this.callback;
+ try {
+ callback();
+ } catch (error) {
+ // TODO(devsnek) remove this if
+ // https://bugs.chromium.org/p/v8/issues/detail?id=8326
+ // is resolved such that V8 triggers the fatal exception
+ // handler for microtasks
+ triggerFatalException(error);
+ } finally {
+ this.emitDestroy();
+ }
+ });
+}
+
function queueMicrotask(callback) {
if (typeof callback !== 'function') {
throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
}
const asyncResource = createMicrotaskResource();
+ asyncResource.callback = callback;
- enqueueMicrotask(() => {
- asyncResource.runInAsyncScope(() => {
- try {
- callback();
- } catch (error) {
- // TODO(devsnek) remove this if
- // https://bugs.chromium.org/p/v8/issues/detail?id=8326
- // is resolved such that V8 triggers the fatal exception
- // handler for microtasks
- triggerFatalException(error);
- } finally {
- asyncResource.emitDestroy();
- }
- });
- });
+ enqueueMicrotask(FunctionBind(runMicrotask, asyncResource));
}
module.exports = {