Repository navigation
Commit 050d985
feat(async-runtime): drain-linger surface + lock-free scheduler internals (#3420)
* feat(async-runtime): 0.2.0 — drain-linger surface + lock-free scheduler internals
Port the napi-async-runtime 0.1.0 -> 0.2.0 delta from the rolldown
integration line (rolldown/napi-3.12.0 @ 9999dad) onto main. The
executor/host contract (AsyncRuntime SPI, configure/install, JsCallback,
consumed API signatures) is unchanged; this is a perf release plus one
new public knob.
Public surface added:
- RuntimeOptions.drain_linger: Duration and
RuntimeOptionsPatch.drain_linger: Option<Duration> — the pool
drainer's idle-linger budget (0 disables lingering), ceiling-clamped
by validation.
- Consts DEFAULT_DRAIN_LINGER_MICROS (500) / MAX_DRAIN_LINGER_MICROS
(100_000) and env name DRAIN_LINGER_ENV
("NAPI_RUNTIME_DRAIN_LINGER_US").
- napi-feature adapter: resolve_drain_linger env resolver, install()
resolves DRAIN_LINGER_ENV at addon load, and
BindingRuntimeConfig.drain_linger_us reports the validated value.
Perf internals (behavior-preserving for hosts):
- Lock-free crossbeam-deque injector queue replacing the mutexed
global queue on the pool path.
- ArcSwapOption spawn path removing the spawn-side lock.
- Retire-by-sequence worker retirement instead of eager teardown.
- Drainer idle-linger: pool drainers linger briefly on an empty queue
(bounded by a frame-residence cap) instead of respawning per wave.
Deviation from the integration branch: crates/async-runtime/Cargo.toml
keeps main's dependency shape (path deps with version = "3" for
napi/napi-derive) instead of the branch's exact =3.12.0/=3.7.0 pins;
new deps arc-swap and crossbeam-deque (non-wasm) are added. In-crate
tests come with the port (327 native tests, consumed_api unchanged).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
* fix(async-runtime): rustfmt drift + widen the Windows timing bound in cooperative-exit residue test
Failure 1: `cargo fmt -- --check` diff at async_runtime.rs:15945 -- the
ported file came from a lineage formatted with an older rustfmt; the
current toolchain joins the producer loop's two-line `while` condition
into one line. Reformatted (this file only; the rest of the workspace
was already fmt-clean).
Failure 2: `cooperative_exit_compensates_blocking_only_residue` timed
out on the msys2 CLANG64 lane at `returned_rx.recv_timeout(2s)` while
`blocking_rx` succeeded. Root cause is wake ROUTING, not just slowness:
on a starved runner the cooperative frame can still be un-parked when
the timer task is scheduled, so the schedule spawns a second drainer;
that drainer then LINGERS as a registered blocking-capable parker, and
`wake_one_blocking` prefers the most recently parked candidate -- the
linger parker absorbs the wake meant for the frame, the drainer runs
the blocking job (blocking_rx passes), and the frame sleeps in its
timer-bounded park until the test's own 120s heap timer, past any sane
recv bound (so merely widening the timeout could not fix this mode).
Harden the test with the module's established `wait_until` parked-count
idiom (as in multi_thread_cooperative_exit_hands_absorbed_wake_to_
parked_driver): require the frame to be the sole registered parker
before scheduling the timer task and again before the blocking wake, so
the wake deterministically targets the frame and its exit compensation
-- the subject under test -- services the residue. Also widen the recv
bounds 2s -> 10s per the module's hang-detector-not-latency-assertion
doctrine. No scheduler changes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent e0b8708 commit 050d985
3 files changed
Lines changed: 1528 additions & 146 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
| |||
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
174 | 180 | | |
175 | 181 | | |
176 | 182 | | |
| |||
179 | 185 | | |
180 | 186 | | |
181 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
182 | 191 | | |
183 | 192 | | |
184 | 193 | | |
| |||
1961 | 1970 | | |
1962 | 1971 | | |
1963 | 1972 | | |
1964 | | - | |
1965 | | - | |
1966 | | - | |
1967 | | - | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
1968 | 1987 | | |
1969 | 1988 | | |
1970 | 1989 | | |
| |||
1987 | 2006 | | |
1988 | 2007 | | |
1989 | 2008 | | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
1990 | 2030 | | |
1991 | 2031 | | |
1992 | 2032 | | |
| |||
3780 | 3820 | | |
3781 | 3821 | | |
3782 | 3822 | | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + | |
| 3826 | + | |
| 3827 | + | |
| 3828 | + | |
| 3829 | + | |
| 3830 | + | |
| 3831 | + | |
| 3832 | + | |
| 3833 | + | |
| 3834 | + | |
| 3835 | + | |
| 3836 | + | |
| 3837 | + | |
| 3838 | + | |
| 3839 | + | |
| 3840 | + | |
| 3841 | + | |
| 3842 | + | |
| 3843 | + | |
| 3844 | + | |
| 3845 | + | |
| 3846 | + | |
| 3847 | + | |
| 3848 | + | |
| 3849 | + | |
| 3850 | + | |
| 3851 | + | |
| 3852 | + | |
| 3853 | + | |
| 3854 | + | |
| 3855 | + | |
| 3856 | + | |
| 3857 | + | |
| 3858 | + | |
| 3859 | + | |
| 3860 | + | |
| 3861 | + | |
| 3862 | + | |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
| 3866 | + | |
| 3867 | + | |
| 3868 | + | |
| 3869 | + | |
| 3870 | + | |
| 3871 | + | |
3783 | 3872 | | |
0 commit comments