Skip to content

perf(loader): dispatch parallel loaders from Rust - #15363

Draft
intellild wants to merge 1 commit into
mainfrom
codex/rust-loader-direct-mpmc
Draft

perf(loader): dispatch parallel loaders from Rust#15363
intellild wants to merge 1 commit into
mainfrom
codex/rust-loader-direct-mpmc

Conversation

@intellild

Copy link
Copy Markdown
Contributor

Summary

  • Dispatch parallel JavaScript loader tasks directly from the Rust loader runner through a generic unbounded MPMC worker queue.
  • Keep persistent JavaScript workers independent from loader-specific registration: each worker receives one native task, executes it, completes it, then calls recv again.
  • Expose loader context and the canonical NormalModule through native-backed accessors so parallel execution does not copy the module or bulk context state through the JavaScript main thread.
  • Keep Rule.use.options in a compiler-owned map on the JavaScript main thread. Native code carries only a u32 handle; a worker requests the value over its existing MessagePort, ordinary values use structured clone, and functions continue to use the synchronous SharedArrayBuffer + Atomics bridge.

Execution flow:

Rust loader runner
  enqueue native task
       ↓
generic unbounded MPMC queue
       ↓
persistent JS worker recv loop
       ↓
native-backed loader context accessors
       ↓
run pitch/normal loader and complete native task

Loader options flow:

Rule.use.options
  stored in main-isolate compiler map
       ↓ u32 handle only
Rust loader metadata / worker task
       ↓
worker requests handle over MessagePort
       ↓
structured clone ordinary values
function handles synchronously call the main isolate

For example, a Babel loader cache hit no longer requires the main JavaScript thread to materialize and forward the parallel loader payload or serialize the options object through V8. A non-parallel loader still receives the original options object identity, while a parallel loader receives a worker-local structured clone with Map, typed arrays, URLs, and function options preserved by the bridge.

Related links

  • Follow-up implementation plan is included in task.md.

Checklist

  • Tests updated.
  • Documentation updated.

Validation:

  • cargo check -p rspack_binding_api -p rspack_core -p rspack_loader_runner -p rspack
  • cargo test -p rspack --test loader --no-run
  • pnpm run build:binding:dev
  • pnpm run build:js
  • pnpm exec rs check --type-check
  • pnpm run test -t "configCases/loader-parallel" (62 tests passed)

by OpenAI Codex

@intellild
intellild force-pushed the codex/rust-loader-direct-mpmc branch from 38a1990 to 1d3fe07 Compare August 28, 2026 02:34
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 70c6e24 to refactor(core): remove BuildInfo clone (#15377) by hardfist

❌ Size increased by 84.13KB from 68.24MB to 68.32MB (⬆️0.12%)

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

⚠️ Note: The latest commit (2fb1390cb6) does not have baseline artifacts. Using commit ced05ad339 for baseline comparison instead. If this seems incorrect, please wait a few minutes and try rerunning the workflow.

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 556.5 KB 0 0
react-10k 5.6 MB 1.3 MB 0 0
react-1k 823.1 KB 218.4 KB 0 0
react-5k 2.7 MB 669.3 KB 0 0
ui-components 4.9 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@intellild
intellild force-pushed the codex/rust-loader-direct-mpmc branch from 2eed0b5 to 70c6e24 Compare August 28, 2026 13:17
@intellild intellild changed the title refactor(loader): dispatch parallel loaders from Rust perf(loader): dispatch parallel loaders from Rust Aug 28, 2026
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