Repository navigation
Conversation
The default parsetree mapper rebuilt every node, list, option and located name, so the built-in PPX and the JSX transform copied the whole tree of every file. Now a node whose parts all come back physically unchanged is returned as is. Parts are mapped in the same order as before, which a trace of every mapper call over the 3038 .res/.resi files in the repository confirms. The PPX overrides for functions, let bindings and structures, and the JSX structure and signature mappers, share the same way. Parsing with the built-in PPX (bsc -bs-ast) on 77 Belt and tests/tests files allocates 8.9% less (2.1% to 12.2% per file), and 16.0% less with -bs-jsx 4. Whole compiles of 56 of them allocate 1.4% less. The JS output and diagnostics are byte-identical; the .ast files hold equal trees, but 37 of 77 differ in bytes, since Marshal records the new sharing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🏠 Internal
Semantic Diff3 commits · Full page Return unchanged parsetree nodes from Ast_mapper as they are5fcc46e · cknitt + Claude · Nov 22, 2026, 14:42 UTC The default parsetree mapper rebuilt every node, list, option and located name, so the built-in PPX and the JSX transform copied the whole tree of every file. Now a node whose parts all come back physically unchanged is returned as is. Parts are mapped in the same order as before, which a trace of every mapper call over the 3038 .res/.resi files in the repository confirms. The PPX overrides for functions, let bindings and structures, and the JSX structure and signature mappers, share the same way. Parsing with the built-in PPX (bsc -bs-ast) on 77 Belt and tests/tests files allocates 8.9% less (2.1% to 12.2% per file), and 16.0% less with -bs-jsx 4. Whole compiles of 56 of them allocate 1.4% less. The JS output and diagnostics are byte-identical; the .ast files hold equal trees, but 37 of 77 differ in bytes, since Marshal records the new sharing. Map long lists in constant stack in the sharing mapsfbb396a · cknitt + Claude · Nov 23, 2026, 06:54 UTC Ast_mapper's map_list and Ext_list's map_sharing recursed once per element, so the built-in PPX needed a stack frame per element of a long array, record type or structure, where master's List.map needed none. Now they recurse over the first 1000 elements only, which allocates nothing for an unchanged list, and continue in a loop after that. The loop keeps the result up to the last change in a reversed list and shares the unchanged rest. Elements are still mapped once each, in list order. map_snd_sharing gets the same fallback, and the JSX transform's concat_map_sharing moves to Ext_list with it. The unit tests check the result, the visiting order and the sharing around the switch from recursion to the loop. Parsing with the built-in PPX now needs about 4k words of stack for an array of 50,000 elements and 8k for a record type of 20,000 fields, where it needed 263k and 66k before (master: under 1k). A 1-million-element array compiles as fast as before, with master's peak memory. JS output and diagnostics are byte-identical on 77 benchmark files, and allocation is unchanged (+0.0004%). ✨ Keep plain recursion in Ext_list.map_sharing and map_snd_sharingc4965ac · cknitt + Claude · Nov 23, 2026, 07:31 UTC · new The depth counter added to every sharing map costs a few instructions per element. That is negligible in the built-in PPX but not in the Lambda and JS passes, which call Ext_list.map_sharing all the time: the CI benchmarks measured +0.12% instructions in total and +1.49% for stress/RefsInLoop. These two maps have recursed once per element since long before this pull request, so they go back to master's code. The fallback stays where this pull request made lists deeper than on master: Ast_mapper's map_list and the JSX transform's concat_map_sharing, which replaced List.map and List.concat_map. Parsing with the built-in PPX still needs about 4k words of stack for a 50,000-element array and 8k for a 20,000-field record type. JS output and diagnostics are byte-identical on 77 benchmark files. |
🎉 Compiler benchmarksAllocated wordsIn total: 624,736,557 → 616,059,543 (-1.39%). Generated projects: 626,380,692 → 623,374,184 (-0.48%). 🎉 Improvement: 156 benchmarks allocate more than 1% less.
246 more changes
InstructionsIn total: 9,172,468,809 → 9,174,033,345 (+0.02%).
10 more changes
Output sizeIn total: 25,963,868 → 25,965,258 (+0.01%).
Pull request c4965ac compared with base 00a687b in this run. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## js-ir-sharing #9395 +/- ##
===============================================
Coverage 82.18% 82.19%
===============================================
Files 460 461 +1
Lines 65577 66055 +478
===============================================
+ Hits 53896 54293 +397
- Misses 11681 11762 +81
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
Ast_mapper's map_list and Ext_list's map_sharing recursed once per element, so the built-in PPX needed a stack frame per element of a long array, record type or structure, where master's List.map needed none. Now they recurse over the first 1000 elements only, which allocates nothing for an unchanged list, and continue in a loop after that. The loop keeps the result up to the last change in a reversed list and shares the unchanged rest. Elements are still mapped once each, in list order. map_snd_sharing gets the same fallback, and the JSX transform's concat_map_sharing moves to Ext_list with it. The unit tests check the result, the visiting order and the sharing around the switch from recursion to the loop. Parsing with the built-in PPX now needs about 4k words of stack for an array of 50,000 elements and 8k for a record type of 20,000 fields, where it needed 263k and 66k before (master: under 1k). A 1-million-element array compiles as fast as before, with master's peak memory. JS output and diagnostics are byte-identical on 77 benchmark files, and allocation is unchanged (+0.0004%). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH Signed-off-by: Christoph Knittel <ck@cca.io>
The depth counter added to every sharing map costs a few instructions per element. That is negligible in the built-in PPX but not in the Lambda and JS passes, which call Ext_list.map_sharing all the time: the CI benchmarks measured +0.12% instructions in total and +1.49% for stress/RefsInLoop. These two maps have recursed once per element since long before this pull request, so they go back to master's code. The fallback stays where this pull request made lists deeper than on master: Ast_mapper's map_list and the JSX transform's concat_map_sharing, which replaced List.map and List.concat_map. Parsing with the built-in PPX still needs about 4k words of stack for a 50,000-element array and 8k for a 20,000-field record type. JS output and diagnostics are byte-identical on 77 benchmark files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH Signed-off-by: Christoph Knittel <ck@cca.io>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The default parsetree mapper rebuilt every node, list, option and located name, so the built-in PPX and the JSX transform copied the whole tree of every file.
Now a node whose parts all come back physically unchanged is returned as is. Parts are mapped in the same order as before; a trace of every mapper call over the 3038
.res/.resifiles in the repository confirms it. The built-in PPX overrides for functions, let bindings and structures, and the JSX structure and signature mappers, share the same way.Measured on 77 Belt and
tests/testsfiles:bsc -bs-ast) allocates 8.9% less (2.1% to 12.2% per file), and 16.0% less with-bs-jsx 4..astfiles hold equal trees, but 37 of 77 differ in bytes, sinceMarshalrecords the new sharing.New test:
tests/ounit_tests/ounit_ast_mapper_tests.mlchecks that the default mapper returns an unchanged structure and signature as they are, that a rewrite rebuilds only the nodes on its path and shares their unchanged siblings, and that parts are mapped in their source order.One thing that changes in principle, though nothing relies on it today:
Ast_helper, which moves@react.component,@res.inlineRecordDefinitionand@asout of the attributes into their own fields. An unchanged node now skips that. It only matters for a node built with record syntax that still holds such an attribute in its list; no code incompiler/orsyntax/builds one.Constant stack for long lists (second and third commits). The two sharing maps this PR introduces in place of
List.mapandList.concat_map,Ast_mapper'smap_listand the JSX transform'sconcat_map_sharing(now inExt_list), recurse over the first 1,000 elements only and continue in a loop after that, so a long list doesn't add a stack frame per element whereList.mapadded none.Ext_list.map_sharingandmap_snd_sharingkeep master's plain recursion: a depth counter in them cost +0.12% instructions in total and +1.49% forstress/RefsInLoop, since the Lambda and JS passes call them constantly.Stacked on the JS IR PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH