Skip to content

Commit

Permalink
lib: make ALS default to AsyncContextFrame
Browse files Browse the repository at this point in the history
PR-URL: #55552
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
  • Loading branch information
Qard authored Nov 2, 2024
1 parent c0db893 commit 51ae576
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
30 changes: 14 additions & 16 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,21 +930,6 @@ and `"` are usable.
It is possible to run code containing inline types by passing
[`--experimental-strip-types`][].

### `--experimental-async-context-frame`

<!-- YAML
added: v22.7.0
-->

> Stability: 1 - Experimental
Enables the use of [`AsyncLocalStorage`][] backed by `AsyncContextFrame` rather
than the default implementation which relies on async\_hooks. This new model is
implemented very differently and so could have differences in how context data
flows within the application. As such, it is presently recommended to be sure
your application behaviour is unaffected by this change before using it in
production.

### `--experimental-default-type=type`

<!-- YAML
Expand Down Expand Up @@ -1663,6 +1648,19 @@ Disable the `node-addons` exports condition as well as disable loading
native addons. When `--no-addons` is specified, calling `process.dlopen` or
requiring a native C++ addon will fail and throw an exception.

### `--no-async-context-frame`

<!-- YAML
added: REPLACEME
-->

> Stability: 2 - Stable
Disables the use of [`AsyncLocalStorage`][] backed by `AsyncContextFrame` and
uses the prior implementation which relied on async\_hooks. The previous model
is retained for compatibility with Electron and for cases where the context
flow may differ. However, if a difference in flow is found please report it.

### `--no-deprecation`

<!-- YAML
Expand Down Expand Up @@ -3051,7 +3049,6 @@ one is included in the list below.
* `--enable-source-maps`
* `--entry-url`
* `--experimental-abortcontroller`
* `--experimental-async-context-frame`
* `--experimental-default-type`
* `--experimental-detect-module`
* `--experimental-eventsource`
Expand Down Expand Up @@ -3097,6 +3094,7 @@ one is included in the list below.
* `--napi-modules`
* `--network-family-autoselection-attempt-timeout`
* `--no-addons`
* `--no-async-context-frame`
* `--no-deprecation`
* `--no-experimental-global-navigator`
* `--no-experimental-repl-await`
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/async_context_frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ActiveAsyncContextFrame extends Map {

function checkEnabled() {
const enabled = require('internal/options')
.getOptionValue('--experimental-async-context-frame');
.getOptionValue('--async-context-frame');

// If enabled, swap to active prototype so we don't need to check status
// on every interaction with the async context frame.
Expand Down
5 changes: 3 additions & 2 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
AddOption(
"--experimental-wasi-unstable-preview1", "", NoOp{}, kAllowedInEnvvar);
AddOption("--expose-gc", "expose gc extension", V8Option{}, kAllowedInEnvvar);
AddOption("--experimental-async-context-frame",
AddOption("--async-context-frame",
"Improve AsyncLocalStorage performance with AsyncContextFrame",
&EnvironmentOptions::async_context_frame,
kAllowedInEnvvar);
kAllowedInEnvvar,
true);
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
AddOption("--frozen-intrinsics",
"experimental frozen intrinsics support",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ const tests = testSets.reduce((m, v) => {
return m;
}, []);

describe('AsyncContextFrame', {
describe('without AsyncContextFrame', {
// TODO(qard): I think high concurrency causes memory problems on Windows
// concurrency: tests.length
}, () => {
for (const test of tests) {
it(test, async () => {
const proc = spawn(python, [
testRunner,
'--node-args=--experimental-async-context-frame',
'--node-args=--no-async-context-frame',
test,
], {
stdio: ['ignore', 'ignore', 'inherit'],
Expand Down

0 comments on commit 51ae576

Please sign in to comment.