Skip to content

feat: rayon parallel wasm - #404

Draft
hitchho wants to merge 5 commits into
prax-wallet:mainfrom
rotkonetworks:rayon-parallel-clean
Draft

feat: rayon parallel wasm#404
hitchho wants to merge 5 commits into
prax-wallet:mainfrom
rotkonetworks:rayon-parallel-clean

Conversation

@hitchho

@hitchho hitchho commented Nov 29, 2025

Copy link
Copy Markdown

pr integrates parallel tx building enabling multithreaded proof generation in the extension and go penumbra in web to go nearly as fast as native(ux bottlenecked by blocktimes and current single action per block design). this pr is still draft pending on parallel wasm primitives to be merged in web repo so package.json can target on actual releases. built demo here.

splits webpack into separate browserConfig and workerConfig configurations. service workers require target: 'webworker' to prevent webpack from generating DOM-based chunk loading code
(document.createElement, document.head.appendChild) which fails in worker contexts.

  • browserConfig - standard browser target for UI entry points
  • workerConfig - WebWorker target for service-worker, wasm-build-action, wasm-build-parallel
  • added dependencies: ['browser'] to ensure worker builds after browser (prevents CleanPlugin race)
  • added CopyPlugin pattern to copy wasm-parallel from @penumbra-zone/wasm package

changed static WASM imports to dynamic import() calls in files that run in service worker context. this prevents webpack from bundling WASM modules into the service worker bundle.

  • src/routes/popup/home/index.tsx - Dynamic import for getAddressByIndex
  • src/state/wallets.ts - Dynamic import for generateSpendKey, getFullViewingKey
  • src/state/tx-validation/assert-valid-plan.ts - Dynamic import for isControlledAddress

new dedicated worker that initializes rayon WASM and builds transactions. the worker is persistent (not terminated after each build) to cache WASM module initialization (~1-2s first load), rayon thread pool and proving keys (~70MB+ loaded from extension storage).

worker listens for multiple messages (no once: true), offscreen-handler.ts maintains persistentWorker reference and error handling recreates worker on fatal errors.

  Service workers cannot use DOM APIs that webpack's default async chunk
  loading generates (document.createElement, etc).

  - Split into browserConfig and workerConfig
  - Use target: 'webworker' for service-worker and wasm-build-action
  - Add dependencies to ensure worker builds after browser (clean order)
  - Update prod and beta configs to handle configuration array
  Static WASM imports cause initialization at module load time, which fails
  in service worker context due to sync WASM instantiation restrictions.

  - Convert getAddressByIndex/getEphemeralByIndex to dynamic imports
  - Convert generateSpendKey/getFullViewingKey/getWalletId to dynamic imports
  - Convert isControlledAddress to dynamic import in validation
  - Make assertValidActionPlans async to support dynamic imports
  - Add wasm-build-parallel.ts worker for rayon-based proving
  - Initialize parallel WASM with SharedArrayBuffer in worker context
  - Handle BUILD_PARALLEL message type in offscreen-handler
  - Load proving keys dynamically based on transaction plan actions
instead of failing with error when user triggers tx while logged out,
now automatically opens login popup window. waits for login then
continues to tx approval. closes window on success, throws if user
closes without logging in.
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