Skip to content

perf(lynx): keep optional worklet runtime cold - #707

Merged
trueadm merged 2 commits into
octanejs:mainfrom
Huxpro:huxcx/perf-lynx-cold-worklets
Aug 11, 2026
Merged

trueadm merged 2 commits into
octanejs:mainfrom
Huxpro:huxcx/perf-lynx-cold-worklets

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a renderer-owned threadFunctionsModule route so the compiler imports thread helpers only when compiled output needs them
  • split Lynx's worklet registry/call bridges into @octanejs/lynx/main-worklets, connected to the ordinary receiver through a late-install capability seam
  • preserve direct, monomorphic publication calls in the no-worklet receiver and upgrade already-created host containers when a static or late worklet chunk appears
  • freeze no-worklet preview/IFR main-thread gzip budgets and assert both absent-feature and worklet-enabled production graphs

This follows the residual investigation in Huxpro/octane#44. It does not revive the receiver-level lazy bridge rejected there: the compiler selects the cold feature module and the ordinary receiver keeps its existing call shape.

Validation

Exact upstream base: 9b147781c9b4ec4df053a059633978ddc0ed922a.

No-worklet production artifacts:

slice base gzip candidate gzip delta
preview main 76,915 B 75,024 B -2.46%
IFR main 81,995 B 79,980 B -2.46%

The background program remains exactly 271,737 raw bytes with identical semantic markers. Its encoded checksum changes and gzip is 73,182 → 73,185 B because optimizing the independent main graph changes Rspack's debug-metadata hash and minifier-local symbol allocation; decoding both artifacts found only that hash plus one-character local renames, with no background source, command, or semantic change. This is the itemized exception allowed by #44's acceptance gate.

Final same-host Lynx-for-Web n=9, base → candidate at 10k rows:

operation base candidate delta
create 1,133 ms 1,144 ms +1.0%
update10th 161 ms 163 ms +1.2%
select 60 ms 59 ms -1.7%
updateStorm 577 ms 590 ms +2.3%
selectStorm 171 ms 173 ms +1.2%

An earlier candidate→base n=9 order measured selectStorm 164 → 171 ms; both orders remain inside the 5% decision boundary. A separate n=20 dual-thread render run measured candidate/base create@10k 135.4/134.4 ms and update@10k 22.5/22.8 ms, with identical command/program/ack/selector counters. Lynx list teardown retained 0 cells.

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted tests:
    • pnpm exec vitest run --project lynx --silent=passed-only (338 tests)
    • affected compiler renderer tests (106 tests)
    • Rspeedy production build/module-graph fixture (5 tests)
    • scoped production-source typecheck and format checks
    • pnpm sync
    • node benchmarks/bench.mjs --only lynx-bundle-size
    • node benchmarks/bench.mjs --only lynx-list --ratios
    • deterministic 1k/10k CRUD/storm counters

Risk / follow-ups

The new renderer descriptor field participates in the normalized cache signature. Renderers that omit it retain byte-for-byte compiler import behavior; the compiler test suite covers that fallback. The feature provider supports both evaluation orders and late chunks, and rejects competing providers.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Changes compiler import routing and Lynx main-thread cross-thread/worklet lifecycle; behavior is heavily tested but regressions could affect worklet-enabled apps or bundle graphs.

Overview
Introduces an optional threadFunctionsModule on universal renderer descriptors so the compiler emits thread-function helper imports only when compiled output needs them, instead of always pulling them through the main renderer module.

For Lynx, worklet registries and cross-thread APIs move to @octanejs/lynx/main-worklets, wired into the ordinary main-thread receiver via a small subscribe/provide capability layer. Bundles with no worklets keep a lightweight stub registry and monomorphic publication paths; when a static or late chunk loads the feature, existing host containers upgrade through a replaceable registry identity without changing receiver call shapes.

lynx-bundle-size gains frozen gzip/raw budgets for no-worklet preview/IFR main slices and asserts the main-thread graph excludes main-worklets / worklets unless the app retains worklet helpers.

Reviewed by Cursor Bugbot for commit 71b758e. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 11, 2026
@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 18:10

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 1321184. Configure here.

Comment thread packages/lynx/package.json Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants