0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/lib
Anna Henningsen ae558af7bc
timers: cross JS/C++ border less frequently
This removes the `process._needImmediateCallback` property
and its semantics of having a 1/0 switch that tells C++ whether
immediates are currently scheduled.

Instead, a counter keeping track of all immediates is created,
that can be increased on `setImmediate()` or decreased when an
immediate is run or cleared.

This is faster, because rather than reading/writing a C++ getter,
this operation can be performed as a direct memory read/write via
a typed array. The only C++ call that is left to make is
activating the native handles upon creation of the first
`Immediate` after the queue is empty.

One other (good!) side-effect is that `immediate._destroyed` now
reliably tells whether an `immediate` is still scheduled to run or not.

Also, as a nice extra, this should make it easier to implement
an internal variant of `setImmediate` for C++ that piggybacks
off the same mechanism, which should be useful at least for
async hooks and HTTP/2.

Benchmark results:

    $ ./node benchmark/compare.js --new ./node --old ./node-master-1b093cb93df0 --runs 10 --filter immediate timers | Rscript benchmark/compare.R
    [00:08:53|% 100| 4/4 files | 20/20 runs | 1/1 configs]: Done
                                                         improvement confidence      p.value
     timers/immediate.js type="breadth" thousands=2000      25.61 %         ** 1.432301e-03
     timers/immediate.js type="breadth1" thousands=2000      7.66 %            1.320233e-01
     timers/immediate.js type="breadth4" thousands=2000      4.61 %            5.669053e-01
     timers/immediate.js type="clear" thousands=2000       311.40 %        *** 3.896291e-07
     timers/immediate.js type="depth" thousands=2000        17.54 %         ** 9.755389e-03
     timers/immediate.js type="depth1" thousands=2000       17.09 %        *** 7.176229e-04
     timers/set-immediate-breadth-args.js millions=5        10.63 %          * 4.250034e-02
     timers/set-immediate-breadth.js millions=10            20.62 %        *** 9.150439e-07
     timers/set-immediate-depth-args.js millions=10         17.97 %        *** 6.819135e-10

PR-URL: https://github.com/nodejs/node/pull/17064
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-11-18 01:50:56 +01:00
..
internal util: emit deprecation code only once 2017-11-16 22:00:24 -08:00
_http_agent.js lib: replace string concatenation with template 2017-11-11 10:52:23 +01:00
_http_client.js lib: replace string concatenation with template 2017-11-17 11:06:01 +01:00
_http_common.js async_hooks: add trace events to async_hooks 2017-11-16 11:46:54 +01:00
_http_incoming.js tools: enable additional eslint rules 2017-10-19 13:54:14 -04:00
_http_outgoing.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
_http_server.js http, stream: writeHWM -> writableHighWaterMark 2017-11-15 19:12:08 +01:00
_stream_duplex.js stream: remove usage of *State.highWaterMark 2017-11-15 14:30:39 +01:00
_stream_passthrough.js
_stream_readable.js stream: remove usage of *State.highWaterMark 2017-11-15 14:30:39 +01:00
_stream_transform.js stream: migrate to internal/errors 2017-10-01 20:37:00 -03:00
_stream_wrap.js lib: move _stream_wrap into internals 2017-10-19 18:06:27 +02:00
_stream_writable.js stream: remove usage of *State.highWaterMark 2017-11-15 14:30:39 +01:00
_tls_common.js tls: implement clientCertEngine option 2017-11-11 13:35:23 -08:00
_tls_legacy.js tools: enable additional eslint rules 2017-10-19 13:54:14 -04:00
_tls_wrap.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
.eslintrc.yaml tools: remove legacy indentation linting 2017-07-30 09:21:52 -07:00
assert.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
async_hooks.js async_hooks: add destroy event for gced AsyncResources 2017-11-16 19:58:00 +01:00
buffer.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
child_process.js lib: replace string concatenation with template 2017-11-11 11:04:00 +01:00
cluster.js lib: use consistent indentation for ternaries 2017-07-07 06:57:16 -07:00
console.js console: avoid adding infinite error listeners 2017-11-08 11:22:44 +00:00
constants.js src: add support to pass flags to dlopen 2017-09-08 17:14:03 -04:00
crypto.js crypto: migrate setFipsCrypto to internal/errors 2017-10-27 08:13:01 -07:00
dgram.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
dns.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
domain.js lib: use destructuring for some constants 2017-10-16 23:34:32 +02:00
events.js events: remove emit micro-optimizations 2017-11-14 10:46:57 -08:00
fs.js stream: remove usage of *State.highWaterMark 2017-11-15 14:30:39 +01:00
http2.js http2: refactor error handling 2017-08-28 00:39:42 +04:00
http.js lib: use destructuring for some constants 2017-10-16 23:34:32 +02:00
https.js tls: implement clientCertEngine option 2017-11-11 13:35:23 -08:00
inspector.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
module.js module: speed up package.json parsing more 2017-11-15 12:01:20 +01:00
net.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
os.js os: migrate node_os.cc to internal/errors 2017-11-02 11:58:38 -07:00
path.js path: remove obsolete comment 2017-11-16 16:30:01 -05:00
perf_hooks.js perf_hooks: implementation of the perf timing API 2017-08-23 16:00:09 -07:00
process.js
punycode.js
querystring.js querystring: convert to using internal/errors 2017-10-28 14:04:53 -04:00
readline.js lib: use destructuring for some constants 2017-10-16 23:34:32 +02:00
repl.js repl: support top-level await 2017-11-16 15:42:46 -08:00
stream.js lib: use destructuring for some constants 2017-10-16 23:34:32 +02:00
string_decoder.js lib: use destructuring for some constants 2017-10-16 23:34:32 +02:00
sys.js
timers.js timers: cross JS/C++ border less frequently 2017-11-18 01:50:56 +01:00
tls.js http, tls: better support for IPv6 addresses 2017-11-02 21:05:20 -04:00
tty.js tty: refactor exports 2017-11-14 17:31:26 -05:00
url.js lib: improve the usage of TypeError[INVALID_ARG_TYPE] 2017-11-12 11:04:06 -08:00
util.js util: runtime deprecation for custom .inspect() 2017-11-16 22:00:39 -08:00
v8.js v8: migrate setFlagsFromString to internal/errors 2017-10-29 17:04:27 -07:00
vm.js vm: deprecate vm.runInDebugContext 2017-10-23 17:17:16 +02:00
zlib.js zlib: gracefully set windowBits from 8 to 9 2017-10-29 20:14:01 +01:00