Skip to content

feat(signals): add a __SOLID_ASYNC__ define that drops async support (PoC) - #5271

Draft
lxsmnsyc wants to merge 1 commit into
solidjs:mainfrom
lxsmnsyc:feat/signals-async-flag
Draft

lxsmnsyc wants to merge 1 commit into
solidjs:mainfrom
lxsmnsyc:feat/signals-async-flag

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Proof of concept: a compile-time flag, __SOLID_ASYNC__, that lets an app's bundler drop the async arm of @solidjs/signals. Opened as a draft to get size numbers. It is not ready to merge.

With define: { __SOLID_ASYNC__: "false" }, every client size scenario loses 630 to 850 B brotli (1.8 to 2.2 KB minified). Without the define, behavior is unchanged and the bundle grows by 141 B minified.

Changes

  • src/globals.d.ts declares __ASYNC__ (internal) and __SOLID_ASYNC__ (set by the app).
  • rollup.config.js replaces __ASYNC__ with (typeof __SOLID_ASYNC__ === "undefined" || __SOLID_ASYNC__). The shipped files work without a define and fold to false with one.
  • handleAsync in core/async.ts returns the result as a sync value when __ASYNC__ is false. Its async arm becomes dead code. This covers every caller: recompute, store projections, deferred.ts and verdict.ts.
  • recompute in core/core.ts skips the handleAsync call and treats a thrown NotReadyError as an ordinary error when __ASYNC__ is false.
  • checkAsyncDisabled in core/dev.ts throws in development when a computation returns a promise or async iterable with async off. recompute and handleAsync both call it, so store projections are covered too.
  • The vitest configs of signals, diagnostics and element define __ASYNC__. SOLID_ASYNC=false pnpm test runs the signals suite with async off.
  • scripts/size/bundle.mjs reads SIZE_DEFINE (JSON) and passes it to Rolldown as transform.define.

Measurements

node scripts/size/size.mjs --no-gate on macOS, Rolldown 1.2.11. Each value is the change from main (caba92afb), in brotli bytes and minified bytes.

Scenario main brotli no define "true" "false"
signals: core floor 7537 +29 / +141 0 / 0 -841 / -2217
signals: + createStore 14543 +29 / +141 0 / 0 -775 / -1993
signals: + isPending/latest 13412 +27 / +141 0 / 0 -850 / -2171
app: render + one signal 9778 +36 / +141 0 / 0 -834 / -2217
app: CSR with Show/For/Loading/Errored/lazy 13774 +52 / +141 0 / 0 -753 / -1999
app: hydrating + every store primitive family 34004 -56 / +141 0 / 0 -752 / -1835
app: compiled CSR (JSX todo app) 26306 -20 / +141 0 / 0 -734 / -1823
app: compiled hydrating 32589 -7 / +141 0 / 0 -724 / -1824
page: base server components 34230 +35 / +141 0 / 0 -662 / -1814
page: live + router 51618 -11 / +141 0 / 0 -759 / -1903
server: renderToString 23791 0 / 0 0 / 0 0 / 0

The other client scenarios fall in the same ranges. The frames and server scenarios do not change.

To reproduce:

pnpm build
cd scripts/size
node size.mjs --no-gate
SIZE_DEFINE='{"__SOLID_ASYNC__":"false"}' node size.mjs --no-gate

Two variants measured and not kept:

  • Guard in handleAsync only. No define costs +47 B minified, and "false" saves 580 to 700 B brotli. The two guards in recompute add about 150 B brotli of savings for +94 B of no-define cost.
  • STATUS_PENDING = __ASYNC__ ? 1 : 0. It saves 0 B. Rolldown does not inline the exported constant across modules, so the roughly 140 & STATUS_PENDING tests stay.

Proof

  • Async on: pnpm test in packages/signals passes (7322 tests). One run had a single failure that passed on the rerun.
  • diagnostics (37 tests) and element (11 tests) pass.
  • Async off: SOLID_ASYNC=false pnpm test fails 3329 tests. Most failures are the checkAsyncDisabled error from tests that use async. The suite has no sync-only subset yet, so the off mode has no passing proof.
  • tsc -p tsconfig.build.json reports no errors.

Cost

  • No define: +141 B minified, +11 to +70 B brotli. This is over the size gate's 20 B minified allowance, so the size check is expected to fail.
  • "true": 0 B.

Risk

  • Rating. High. The change is in recompute and handleAsync, which every computation runs.
  • Async on. With the flag on or undefined, the guards are true and the code paths match main.
  • Async off in production. A promise is stored as a value with no error. Only development throws.
  • NotReadyError with async off. recompute treats it as an error. Code that throws one by hand, outside the async paths, gets an error status instead of pending.
  • Libraries. A library that uses async, such as @solidjs/router loaders, breaks when the app defines "false".
  • Server and client. A server that streams async values needs async on the client too. The flag must match on both builds.
  • Revert. The change reverts alone. It changes no stored data or format.

Not done

  • Vite plugin option. @solidjs/vite-plugin lives outside this repo. An async: false option would set the define for the client build, the SSR build and optimizeDeps.
  • Bundle analysis. Async is decided by what a function returns at runtime, so analysis cannot prove an app is sync. It could warn when it finds no imports of Loading, isPending, latest, action, createOptimistic or refresh.
  • Pending branches. The STATUS_PENDING tests in core.ts, scheduler.ts and async.ts stay. Removing them needs an __ASYNC__ && guard at each site, or a build tier selected by an export condition.
  • No-define cost. A prebuilt no-async tier, like the observe tier, would cost 0 B by default. It doubles the prod and observe builds.
  • Sync test subset. A run of the sync tests with async off.
  • Size gate. Caps are not changed.

🤖 Generated with Claude Code

- Defining `__SOLID_ASYNC__` as `false` folds out the async arm of
  `handleAsync` and the thenable and `NotReadyError` paths of `recompute`.
- Development throws when a computation returns a promise or async
  iterable with async off.
- `scripts/size/bundle.mjs` reads `SIZE_DEFINE` to measure scenarios
  under an app's defines.

Proof of concept for size measurements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3de0ef5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@solidjs/signals Minor
@solidjs/web Minor
@solidjs/diagnostics Minor
solid-js Minor
@solidjs/universal Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed

codspeed Bot commented Nov 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Upgrade your CodSpeed plugin for Node.js 24

@codspeed/* 5.4.0 is only tested on Node.js 18, 20, and 22, so your Node.js 24 measurements may be inaccurate. Upgrade your @codspeed/* packages to 6.0.0 or later.

See affected benchmarks

✅ 205 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing lxsmnsyc:feat/signals-async-flag (3de0ef5) with main (caba92a)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant