Repository navigation
perf: evaluate codeSplitting test/name functions before the assignment loop - #10740
Closed
MarshallOfSound wants to merge 1 commit into
Closed
MarshallOfSound wants to merge 1 commit into
MarshallOfSound wants to merge 1 commit into
Conversation
MarshallOfSound
requested review from
IWANABETHATGUY,
hyfdev and
shulaoda
as code owners
August 22, 2026 08:42
Merging this PR will not alter performance
Comparing Footnotes
|
IWANABETHATGUY
added a commit
that referenced
this pull request
Aug 24, 2026
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. <details><summary>benchmark</summary> 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. </details> This and #10740 solve the same problem and cannot both land.
Contributor
Author
|
Superseded by #10745 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Function-valued
codeSplitting.groups[].test/.nameare JS callbacks, andbuild_module_groupsawaited them one (module × group) pair at a time inside the assignment loop — one main-thread round trip each. On a large app with a few function groups that is ~10⁵ sequential hops between link and chunk rendering.This evaluates them before the loop and caches the results: calls are dispatched in bounded batches, one callback function at a time (every module for group 0's
test, then group 1's, …, then thenamecallbacks likewise), each in the existingstable_idorder. A given JS function's queued calls run in dispatch order, so a stateful callback still sees a deterministic sequence; different functions are never in flight together. The set of calls, group membership and output are unchanged.Synthetic project (20k leaf modules shared across 200 dynamic entries, 6 groups with function
test+name, 95,545 callback invocations), secondgenerate()on a warm graph, output byte-identical:generate()On the real app this came from (~20k modules, 3 function groups) it removes ~3 s from a production build.
fixture
AI-assisted (Claude Code); reviewed and benchmarked by me.