Skip to content

src: lazily start V8 platform worker threads - #66147

Closed
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/lazy-v8-platform-threads-0e63
Closed

anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/lazy-v8-platform-threads-0e63

Conversation

@anonrig

@anonrig anonrig commented Sep 20, 2026

Copy link
Copy Markdown
Member

This stops NodePlatform from creating the V8 worker pool and the delayed-task libuv loop during bootstrap, then blocking until those workers are ready.

Workers are started as tasks are posted, up to --v8-pool-size. The delayed-task loop is started only when a delayed worker task is first scheduled. NumberOfWorkerThreads() now returns the configured pool size. It previously returned started threads, which included the scheduler thread.

V8 still posts compile and GC jobs during isolate initialization (OptimizingCompileTaskExecutor, concurrent baseline/maglev, scavenger, MemoryPool::PostDelayedReleaseTask). A default node -e process therefore still ends up with 4 node-V8Worker threads plus DelayedTaskSchedulerWorker. The libuv FS/DNS/crypto pool (UV_THREADPOOL_SIZE) is unchanged.

Benchmarks

A/B on the same machine, same configure flags (--ninja --without-intl --without-npm --without-node-snapshot --without-node-code-cache --v8-disable-temporal-support). Only src/node_platform.{cc,h} differs. Snapshot-less startup is slower than a production build; the comparison is relative.

benchmark/misc/startup-core.js (ops/sec, higher is better)

Script Eager Lazy Delta
empty.mjs mode=process n=30 18.87 18.67 -1.1%
semicolon.js mode=process n=30 22.17 21.50 -3.0%
require-builtins.js mode=process n=30 9.94 10.31 +3.8%

Wall-clock spawn (n=40, warmup=5, lower is better)

Script Eager mean Lazy mean Delta
benchmark/fixtures/empty.mjs 49.99 ms 49.33 ms -1.3%
test/fixtures/semicolon.js 45.58 ms 45.64 ms +0.1%
node -e '' 50.01 ms 51.22 ms +2.4%

Threads and RSS after user JS starts (/proc/self/status)

Metric Eager Lazy
Threads 7 7
RSS 49104 kB 49340 kB
Names node-MainThread, 4× node-V8Worker, DelayedTaskSchedulerWorker, SignalInspector same

Startup and RSS are within noise. Steady-state thread count is unchanged because V8 posts platform jobs during isolate init. The remaining effects are: no constructor barrier, on-demand creation for embedders that do not immediately initialize an isolate, and a correct worker-count for CreateJob.

Tests

  • cctest --gtest_filter=PlatformTest.Lazy* passed
  • test/parallel/test-v8-platform-lazy-workers.js passed
  • test/parallel/test-v8-flag-pool-size-0.js passed

The V8 platform currently creates the configured worker threads and a
dedicated libuv loop for delayed tasks during Node.js bootstrap, then
waits for those workers to become ready. Short-lived processes often
never post background work, so this wastes startup time and RSS.

Start workers as tasks are posted, up to the configured pool size, and
create the delayed-task loop only when a delayed task is first
scheduled. NumberOfWorkerThreads() now reports the configured size
instead of the number of already-started threads (which previously
included the scheduler thread).

Assisted-by: Cursor Grok 4.6

Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency. labels Sep 20, 2026
@anonrig anonrig closed this Sep 20, 2026
@anonrig

anonrig commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

Closing: A/B numbers show no startup, RSS, or thread-count win. V8 still starts the platform workers and delayed-task loop during isolate init.

Will look for a change that actually moves those metrics.

@anonrig
anonrig deleted the cursor/lazy-v8-platform-threads-0e63 branch September 20, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants