Skip to content

perf: batch codeSplitting group test / name calls - #10745

Merged
IWANABETHATGUY merged 1 commit into
mainfrom
perf/batch-code-splitting-callbacks
Aug 24, 2026
Merged

IWANABETHATGUY merged 1 commit into
mainfrom
perf/batch-code-splitting-callbacks

Conversation

@IWANABETHATGUY

@IWANABETHATGUY IWANABETHATGUY commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Function-valued codeSplitting.groups[].test and .name are JS callbacks, and each call crossed the napi boundary on its own, so a build with M modules and G function groups paid M * G crossings before it rendered a chunk.

The JS side now hands the binding one shim per callback that takes the whole id array and loops in JS, so a group crosses at most twice. A group's calls are contiguous now instead of interleaved with the other groups', and a group's whole test pass runs before its first name call, but each callback still sees its own ids in stable_id order.

benchmark

20k leaf modules shared across 200 dynamic entries, 6 groups with function test + name. Best of 11 generate() calls, release builds of all three, byte-identical output.

generate() the 86,856 test calls alone
main 1243 ms 803 ms
#10740 412 ms 57 ms
this PR 361 ms 18 ms

The second column comes from timing the same app again with the six test functions replaced by regexes that match identically. The output stays byte-identical, so the only difference is that those calls never leave Rust. #10740 overlaps one crossing per call with try_join_all, which leaves 656 ns each; batching the payload leaves 207 ns.

What is left is mostly not the user's code — replaying those same 86,856 calls in plain JS costs 0.7 ms, so ~95% of the 18 ms is marshalling one id string per module per group. Sending the id list once for all groups would cut that further.

Benchmark produced with Claude Code.

This and #10740 solve the same problem and cannot both land.

@IWANABETHATGUY
IWANABETHATGUY force-pushed the perf/batch-code-splitting-callbacks branch from 4b67b8d to 60ca414 Compare August 23, 2026 12:58
Base automatically changed from perf/hoist-manual-code-splitting-invariants to main August 23, 2026 16:03
IWANABETHATGUY added a commit that referenced this pull request Aug 23, 2026
)

`ChunkingContext` was rebuilt for every (module, group) pair, and the `is_included` / already-assigned checks ran per module inside the loop.

No behavior change. This is preparation for #10745.
@IWANABETHATGUY
IWANABETHATGUY force-pushed the perf/batch-code-splitting-callbacks branch from 60ca414 to 4283f4e Compare August 23, 2026 16:05
@netlify

netlify Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 842d9fc
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a8c5f26582cff0008c12627

@IWANABETHATGUY
IWANABETHATGUY force-pushed the perf/batch-code-splitting-callbacks branch 3 times, most recently from c14c740 to 79c4b10 Compare August 24, 2026 02:34
@IWANABETHATGUY
IWANABETHATGUY force-pushed the perf/batch-code-splitting-callbacks branch 2 times, most recently from 42f4080 to f75d500 Compare August 24, 2026 02:56
@IWANABETHATGUY
IWANABETHATGUY marked this pull request as ready for review August 24, 2026 03:22
@codspeed

codspeed Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing perf/batch-code-splitting-callbacks (842d9fc) with main (2742ce1)2

Open in CodSpeed

Footnotes

  1. 10 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. ↩

  2. No successful run was found on main (c9d6f23) during the generation of this report, so 2742ce1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM other than #10745 (comment) needs quick conclusion.

Function-valued `codeSplitting.groups[].test` and `.name` are JS callbacks, and
each call crossed the napi boundary on its own, so a build with M modules and G
function groups paid M * G crossings before it rendered a chunk.

The JS side now hands the binding one shim per callback that takes the whole id
array and loops in JS, so a group crosses at most twice. Each callback still
sees its own ids in `stable_id` order, but a group's whole `test` pass now runs
before its first `name` call, where the old loop interleaved the two per module.

On a synthetic app (20k leaf modules across 200 dynamic entries, 6 groups with
function `test` + `name`, 95,545 calls) the output is byte-identical and the
cost attributable to the callbacks drops from 901 ms to 26 ms.
@IWANABETHATGUY
IWANABETHATGUY force-pushed the perf/batch-code-splitting-callbacks branch from f75d500 to 842d9fc Compare August 24, 2026 15:11
@IWANABETHATGUY
IWANABETHATGUY merged commit f86be54 into main Aug 24, 2026
36 checks passed
@IWANABETHATGUY
IWANABETHATGUY deleted the perf/batch-code-splitting-callbacks branch August 24, 2026 15:32
IWANABETHATGUY added a commit that referenced this pull request Aug 24, 2026
…wrong type (#10753)

One call classifies or names a whole batch, so napi validates the array
and reports its type rather than the offending element's. A plain JS
config that returned a string from `test` produced `The function
returned object, but expected object`.

Both shims now check each result before the batch crosses, so the error
names the module and the type it expected. `test` crosses as a byte
array, which also drops a per-element conversion. `name` still crosses
as strings.

refs #10745
Brooooooklyn added a commit that referenced this pull request Aug 25, 2026
Two CI failures from the main sync:
- rolldown-binding.wasip1.d.cts is a branch-only flavor file, so main's
  batched BindingMatchGroup signatures (#10745) never reached it; the
  threaded and native declaration flavors were already regenerated.
- RUSTSEC-2026-0221: event-listener 5.4.1 marks StackSlot Send/Sync
  unconditionally; 5.4.2 is the patched release (lock-only bump).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
@rolldown-guard rolldown-guard Bot mentioned this pull request Aug 26, 2026
shulaoda added a commit that referenced this pull request Aug 26, 2026
## [1.2.6] - 2026-08-26

### 🚀 Features

- minify: support property name mangling (#10374) by @Dunqing
- add `tsconfig: string` option to `transform` (#10727) by @sapphi-red
- rolldown_plugin_vite_transform: add `tsconfig` option (#10725) by @sapphi-red
- rolldown_plugin_vite_resolve: add top-level `tsconfig` option (#10724) by @sapphi-red
- dev: expose module graph queries on the dev engine handle (#10716) by @h-a-n-a

### 🐛 Bug Fixes

- dev: assign import bindings before initializing dependencies (#10783) by @h-a-n-a
- dev: copy star re-exports before initializing dependencies (#10761) by @h-a-n-a
- dev: register an empty exports object for a module without exports (#10772) by @h-a-n-a
- name the module when a `codeSplitting` group callback returns a wrong type (#10753) by @IWANABETHATGUY
- dev: map dev rename events like build watch (#10758) by @shulaoda
- clear resolution cache when `TsconfigCache::clear` is called (#10726) by @sapphi-red
- dev: resolve in-flight `ensureLatestBuildOutput` when the engine closes (#10730) by @h-a-n-a
- binding: replace undeclared BindingErrorsOr with BindingResult in hook types (#10717) by @h-a-n-a

### 🚜 Refactor

- rolldown_fs_watcher: collapse fs-watcher backends behind a single FsWatcher (#10735) by @shulaoda
- hoist invariants out of the `codeSplitting` group loop (#10744) by @IWANABETHATGUY

### 📚 Documentation

- document shared notify rename mapping (#10759) by @shulaoda
- update watch-mode internals for unified FsWatcher (#10736) by @shulaoda

### ⚡ Performance

- batch `codeSplitting` group `test` / `name` calls (#10745) by @IWANABETHATGUY
- deduplicate used symbol ref readers (#10742) by @Boshen
- reduce release debug formatting (#10728) by @Boshen
- enable compiler cache via `module.enableCompileCache()` (#10678) by @btea
- deduplicate regress codegen (#10732) by @Boshen

### 🧪 Testing

- define: add expected failure for default parameter scope (#10780) by @hyfdev
- use an absolute filename for transform tsconfig path (#10782) by @shulaoda

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.147.0 (#10767) by @camc314
- deps: update resolver dependencies (#10766) by @Boshen
- deps: update rollup submodule for tests to v4.62.5 (#10770) by @rolldown-guard[bot]
- deps: update dependency vite-plus to ^0.3.0 (#10757) by @renovate[bot]
- deps: update npm packages (#10750) by @renovate[bot]
- deps: update rust crates (#10748) by @renovate[bot]
- deps: update rust crate napi to v3.12.2 (#10738) by @renovate[bot]
- deps: update dependency rust to v1.98.0 (#10733) by @renovate[bot]
- wasi: cap each Node Test attempt with timeout to survive hangs (#10709) by @hyfdev

Co-authored-by: shulaoda <[email protected]>
IWANABETHATGUY added a commit that referenced this pull request Sep 20, 2026
A function `sourcemapIgnoreList` ran once per source of a sourcemap, and
the Rust loop awaited each call before it started the next, so a chunk
with N sources paid N serial napi crossings.

The JS side now takes the whole source list in one shim and loops in JS.
The shim answers with one byte per source, which crosses as a buffer
instead of as N tagged values. A boolean, string or regular expression
still takes the static path in Rust and makes no call.

refs #10745
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.

2 participants