Skip to content

Return unchanged parsetree nodes from Ast_mapper as they are - #9395

Closed
cknitt wants to merge 3 commits into
js-ir-sharingfrom
parsetree-mapper-sharing
Closed

cknitt wants to merge 3 commits into
js-ir-sharingfrom
parsetree-mapper-sharing

Conversation

@cknitt

@cknitt cknitt commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

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/.resi files 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/tests files:

  • Parsing with the built-in PPX (bsc -bs-ast) allocates 8.9% less (2.1% to 12.2% per file), and 16.0% less with -bs-jsx 4.
  • Whole compiles allocate 1.4% less.
  • 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.

New test: tests/ounit_tests/ounit_ast_mapper_tests.ml checks 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:

  • The default mapper used to rebuild value descriptions, value bindings, type declarations, fields and constructors through Ast_helper, which moves @react.component, @res.inlineRecordDefinition and @as out 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 in compiler/ or syntax/ builds one.

Constant stack for long lists (second and third commits). The two sharing maps this PR introduces in place of List.map and List.concat_map, Ast_mapper's map_list and the JSX transform's concat_map_sharing (now in Ext_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 where List.map added none. Ext_list.map_sharing and map_snd_sharing keep master's plain recursion: a depth counter in them cost +0.12% instructions in total and +1.49% for stress/RefsInLoop, since the Lambda and JS passes call them constantly.

  • Parsing with the built-in PPX needs about 4k words of stack for a 50,000-element array and 8k for a 20,000-field record type, instead of 263k and 66k without the loop (master: under 1k).
  • A 1-million-element array compiles in 3.1–3.3 s (master 3.6 s), with about master's peak memory (1,005 MB vs 996 MB; 1,054 MB without the loop).
  • Allocation on the 77 files is unchanged (+0.0007%), and the output is byte-identical.
  • Unit tests check the result, the visiting order and the sharing around the switch from recursion to the loop, for lists of up to 5,000 elements.

Stacked on the JS IR PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH

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>
@cknitt
cknitt added this pull request to stack #9397 November 23, 2026 06:35
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Return unchanged parsetree nodes from the built-in PPX and JSX passes instead of copying them, so parsing allocates about 9% less.

Semantic Diff

3 commits · Full page

Return unchanged parsetree nodes from Ast_mapper as they are

5fcc46e · 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 maps

fbb396a · 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_sharing

c4965ac · 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.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🎉 Compiler benchmarks

Allocated words

In 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.

Benchmark Base Head Change
parse/Napkinscript.res 10,716,173 9,619,983 -10.23%
parse/RedBlackTreeNoComments.res 355,139 323,864 -8.81%
parse/RedBlackTree.res 362,852 331,502 -8.64%
parse/HeroGraphic.res 1,854,031 1,746,215 -5.82%
packages/@rescript/belt/src/Belt_List.resi 758,744 733,439 -3.34%
stress/ListLiteral.res 3,205,473 3,106,447 -3.09%
packages/@rescript/belt/src/Belt_Array.resi 650,336 630,703 -3.02%
packages/@rescript/runtime/Stdlib_List.resi 409,863 397,560 -3.00%
stress/NestedClosures.res 10,073,681 9,775,226 -2.96%
packages/@rescript/runtime/Stdlib_Array.resi 728,603 708,673 -2.74%
246 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 328,324 319,498 -2.69%
packages/@rescript/belt/src/Belt_MapString.resi 391,308 380,871 -2.67%
packages/@rescript/belt/src/Belt_MapInt.resi 391,351 380,914 -2.67%
packages/@rescript/runtime/Stdlib_TypedArray.res 785,161 764,297 -2.66%
packages/@rescript/runtime/Stdlib_Date.resi 614,248 598,208 -2.61%
packages/@rescript/belt/src/Belt_Map.resi 579,471 564,480 -2.59%
packages/@rescript/belt/src/Belt_MapDict.resi 513,298 500,194 -2.55%
packages/@rescript/runtime/Stdlib_Console.resi 411,610 401,326 -2.50%
packages/@rescript/belt/src/Belt_MutableSet.resi 397,546 387,771 -2.46%
packages/@rescript/belt/src/Belt_MutableMapString.resi 314,993 307,264 -2.45%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 315,111 307,382 -2.45%
packages/@rescript/belt/src/Belt_SetDict.resi 402,680 392,819 -2.45%
packages/@rescript/runtime/Stdlib_String.resi 497,477 485,336 -2.44%
packages/@rescript/belt/src/Belt_SetString.resi 259,922 253,665 -2.41%
packages/@rescript/belt/src/Belt_SetInt.resi 260,049 253,792 -2.41%
packages/@rescript/belt/src/Belt_MutableSetString.resi 264,996 258,717 -2.37%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 265,113 258,834 -2.37%
packages/@rescript/belt/src/Belt_Set.resi 437,438 427,267 -2.33%
packages/@rescript/runtime/Stdlib_Result.resi 296,377 289,513 -2.32%
packages/@rescript/belt/src/Belt_MutableMap.resi 395,444 386,309 -2.31%
packages/@rescript/runtime/Stdlib_Option.resi 236,507 231,278 -2.21%
stress/LetRec.res 30,319,500 29,649,363 -2.21%
packages/@rescript/runtime/Stdlib_BigInt.resi 186,569 182,474 -2.19%
packages/@rescript/belt/src/Belt_Option.resi 243,374 238,033 -2.19%
packages/@rescript/runtime/Stdlib_Date.res 550,783 538,852 -2.17%
packages/@rescript/runtime/Stdlib_Promise.resi 356,017 348,325 -2.16%
packages/@rescript/runtime/Stdlib_Console.res 370,169 362,454 -2.08%
packages/@rescript/runtime/Stdlib_Int.resi 206,103 201,809 -2.08%
packages/@rescript/runtime/Pervasives.res 239,795 234,827 -2.07%
packages/@rescript/runtime/Stdlib_JsError.resi 184,968 181,150 -2.06%
packages/@rescript/belt/src/Belt_MutableQueue.resi 207,326 203,068 -2.05%
packages/@rescript/runtime/Stdlib_Symbol.resi 160,141 156,860 -2.05%
packages/@rescript/runtime/Stdlib_Dict.resi 240,779 235,869 -2.04%
packages/@rescript/runtime/Stdlib_DataView.resi 268,044 262,655 -2.01%
packages/@rescript/runtime/Stdlib_Array.res 1,252,849 1,227,691 -2.01%
packages/@rescript/belt/src/Belt_internalAVLtree.resi 452,423 443,367 -2.00%
packages/@rescript/runtime/Stdlib_JSON.resi 237,027 232,285 -2.00%
packages/@rescript/runtime/Stdlib_Float.resi 194,292 190,414 -2.00%
packages/@rescript/belt/src/Belt_HashMap.resi 296,908 291,011 -1.99%
packages/@rescript/runtime/Stdlib_String.res 500,391 490,467 -1.98%
packages/@rescript/runtime/Stdlib_Promise.res 352,188 345,233 -1.97%
packages/@rescript/belt/src/Belt_SortArray.resi 253,942 248,951 -1.97%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 234,376 229,785 -1.96%
packages/@rescript/runtime/Stdlib_Math.res 325,744 319,398 -1.95%
build/clean 232,124,939 227,725,141 -1.90%
packages/@rescript/belt/src/Belt_Array.res 2,079,003 2,040,188 -1.87%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 436,679 428,662 -1.84%
packages/@rescript/runtime/Stdlib_Iterator.resi 159,246 156,348 -1.82%
packages/@rescript/runtime/Dom.res 1,071,562 1,052,069 -1.82%
packages/@rescript/runtime/Stdlib_Set.resi 228,953 224,802 -1.81%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 572,341 562,012 -1.80%
packages/@rescript/belt/src/Belt_SortArrayInt.res 1,288,238 1,265,122 -1.79%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res 404,730 397,469 -1.79%
packages/@rescript/belt/src/Belt_SortArrayString.res 1,290,034 1,266,924 -1.79%
packages/@rescript/belt/src/Belt_internalAVLset.resi 354,869 348,518 -1.79%
packages/@rescript/runtime/Stdlib_DataView.res 230,296 226,234 -1.76%
packages/@rescript/belt/src/Belt_SortArray.res 1,389,544 1,365,159 -1.75%
packages/@rescript/runtime/Stdlib_Nullable.resi 199,672 196,173 -1.75%
packages/@rescript/runtime/Stdlib_Map.resi 217,108 213,351 -1.73%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,800 184,560 -1.73%
packages/@rescript/runtime/JsxDOMStyle.res 1,935,489 1,902,302 -1.71%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res 372,085 365,713 -1.71%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 177,818 174,790 -1.70%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 402,392 395,580 -1.69%
packages/@rescript/runtime/Stdlib_Null.resi 204,431 200,983 -1.69%
packages/@rescript/belt/src/Belt_Result.resi 240,168 236,186 -1.66%
packages/@rescript/belt/src/Belt_Id.resi 260,286 256,040 -1.63%
packages/@rescript/runtime/Primitive_object.res 1,118,626 1,100,443 -1.63%
packages/@rescript/belt/src/Belt_HashMapString.resi 213,714 210,264 -1.61%
packages/@rescript/belt/src/Belt_HashMapInt.resi 213,828 210,378 -1.61%
packages/@rescript/runtime/Stdlib_List.res 2,583,889 2,542,613 -1.60%
packages/@rescript/runtime/Stdlib_Symbol.res 146,501 144,218 -1.56%
packages/@rescript/runtime/RescriptTools_Docgen.resi 273,524 269,357 -1.52%
stress/InlineChain.res 3,249,991 3,200,729 -1.52%
packages/@rescript/runtime/Stdlib_Global.resi 155,548 153,210 -1.50%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res 380,770 375,057 -1.50%
packages/@rescript/runtime/Primitive_option.res 292,684 288,329 -1.49%
packages/@rescript/runtime/JsxEvent.res 1,089,069 1,072,880 -1.49%
packages/@rescript/belt/src/Belt_List.res 3,059,356 3,014,397 -1.47%
packages/@rescript/runtime/Stdlib_Temporal_Common.res 366,658 361,275 -1.47%
packages/@rescript/runtime/RescriptTools_Docgen.res 283,576 279,506 -1.44%
packages/@rescript/runtime/Primitive_js_extern.res 239,729 236,331 -1.42%
packages/@rescript/runtime/Stdlib_Set.res 210,675 207,705 -1.41%
packages/@rescript/belt/src/Belt_Range.resi 176,657 174,174 -1.41%
packages/@rescript/runtime/Stdlib_Intl_Locale.res 198,058 195,276 -1.40%
packages/@rescript/belt/src/Belt_internalAVLset.res 2,781,376 2,742,489 -1.40%
packages/@rescript/runtime/Stdlib_RegExp.res 163,608 161,323 -1.40%
packages/@rescript/belt/src/Belt_HashSet.resi 222,778 219,667 -1.40%
packages/@rescript/runtime/Primitive_module.res 328,211 323,636 -1.39%
packages/@rescript/belt/src/Belt_internalAVLtree.res 3,392,692 3,345,690 -1.39%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res 318,742 314,344 -1.38%
packages/@rescript/runtime/Stdlib_IteratorObject.res 250,042 246,661 -1.35%
packages/@rescript/runtime/Stdlib_Lazy.res 218,326 215,382 -1.35%
packages/@rescript/runtime/Stdlib_Map.res 205,333 202,587 -1.34%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res 389,589 384,478 -1.31%
packages/@rescript/runtime/Stdlib_BigInt.res 205,859 203,192 -1.30%
packages/@rescript/runtime/Stdlib_Intl_Common.res 154,350 152,370 -1.28%
packages/@rescript/runtime/Stdlib_Float.res 217,693 214,915 -1.28%
packages/@rescript/runtime/Primitive_hash.res 941,376 929,405 -1.27%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,553 173,353 -1.25%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,666 173,466 -1.25%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res 201,879 199,359 -1.25%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,281 167,175 -1.24%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,406 147,549 -1.24%
packages/@rescript/belt/src/Belt_internalBuckets.res 941,256 929,601 -1.24%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res 180,454 178,236 -1.23%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res 306,084 302,324 -1.23%
packages/@rescript/belt/src/Belt_MutableSet.res 1,849,986 1,827,388 -1.22%
packages/@rescript/belt/src/Belt_MutableSetInt.res 1,617,782 1,598,114 -1.22%
packages/@rescript/belt/src/Belt_MutableSetString.res 1,619,028 1,599,360 -1.21%
packages/@rescript/runtime/Stdlib_JSON.res 293,836 290,287 -1.21%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,925 157,994 -1.21%
packages/@rescript/belt/src/Belt_HashSetString.res 830,258 820,260 -1.20%
packages/@rescript/belt/src/Belt_HashSetInt.res 829,941 819,947 -1.20%
packages/@rescript/belt/src/Belt_HashMapInt.res 1,034,742 1,022,462 -1.19%
packages/@rescript/belt/src/Belt_MutableQueue.res 767,304 758,200 -1.19%
packages/@rescript/belt/src/Belt_HashMapString.res 1,035,454 1,023,174 -1.19%
packages/@rescript/belt/src/Belt_HashMap.res 1,171,954 1,158,062 -1.19%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,775 121,320 -1.19%
packages/@rescript/belt/src/Belt_HashSet.res 955,800 944,539 -1.18%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,925 163,974 -1.18%
packages/@rescript/runtime/Stdlib_Generator.resi 160,547 158,664 -1.17%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,577 167,602 -1.16%
packages/@rescript/runtime/Stdlib_Int.res 447,755 442,542 -1.16%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,695 167,720 -1.16%
packages/@rescript/runtime/Stdlib_Type.res 199,508 197,190 -1.16%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res 169,815 167,850 -1.16%
packages/@rescript/runtime/Primitive_exceptions.res 198,712 196,467 -1.13%
packages/@rescript/runtime/Stdlib_Global.res 141,543 139,950 -1.13%
packages/@rescript/belt/src/Belt_internalSetBuckets.res 682,861 675,203 -1.12%
packages/@rescript/runtime/Stdlib_Dict.res 319,171 315,623 -1.11%
packages/@rescript/belt/src/Belt_Range.res 282,044 278,934 -1.10%
packages/@rescript/belt/src/Belt_internalMapInt.res 1,372,468 1,357,492 -1.09%
packages/@rescript/belt/src/Belt_internalMapString.res 1,374,312 1,359,336 -1.09%
packages/@rescript/belt/src/Belt_Id.res 288,447 285,343 -1.08%
packages/@rescript/runtime/Stdlib_JsError.res 226,656 224,254 -1.06%
packages/@rescript/runtime/Stdlib_Intl_Collator.res 178,657 176,777 -1.05%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res 266,731 263,943 -1.05%
packages/@rescript/belt/src/Belt_Set.res 838,154 829,401 -1.04%
packages/@rescript/belt/src/Belt_internalSetInt.res 713,019 705,698 -1.03%
packages/@rescript/belt/src/Belt_internalSetString.res 714,210 706,889 -1.03%
packages/@rescript/belt/src/Belt_MutableMap.res 1,270,625 1,257,611 -1.02%
packages/@rescript/runtime/Stdlib_Bool.resi 116,818 115,629 -1.02%
packages/@rescript/runtime/Primitive_bigint.res 174,933 173,157 -1.02%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,493 134,122 -1.01%
packages/@rescript/belt/src/Belt_Map.res 959,136 949,472 -1.01%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res 154,530 152,985 -1.00%
packages/@rescript/runtime/Stdlib_Type.resi 135,946 134,593 -1.00%
packages/@rescript/runtime/Primitive_array.res 188,579 186,712 -0.99%
packages/@rescript/runtime/Primitive_list.res 199,295 197,322 -0.99%
packages/@rescript/runtime/Dom_storage.res 165,322 163,699 -0.98%
packages/@rescript/belt/src/Belt_MutableStack.res 379,019 375,303 -0.98%
packages/@rescript/belt/src/Belt_internalBuckets.resi 223,042 220,879 -0.97%
packages/@rescript/belt/src/Belt_SetInt.res 1,259,171 1,246,984 -0.97%
packages/@rescript/belt/src/Belt_SetString.res 1,259,900 1,247,713 -0.97%
packages/@rescript/runtime/Stdlib_Option.res 734,852 727,761 -0.96%
packages/@rescript/belt/src/Belt_SetDict.res 1,413,193 1,399,686 -0.96%
packages/@rescript/belt/src/Belt_Int.resi 149,771 148,346 -0.95%
packages/@rescript/belt/src/Belt_Float.resi 151,251 149,826 -0.94%
packages/@rescript/runtime/Stdlib_Nullable.res 325,361 322,315 -0.94%
packages/@rescript/belt/src/Belt_MapDict.res 1,593,012 1,578,116 -0.94%
packages/@rescript/belt/src/Belt_Option.res 381,610 378,060 -0.93%
packages/@rescript/belt/src/Belt_MutableMapInt.res 1,127,820 1,117,397 -0.92%
packages/@rescript/belt/src/Belt_MutableMapString.res 1,128,097 1,117,674 -0.92%
packages/@rescript/runtime/Primitive_int.res 169,401 167,841 -0.92%
packages/@rescript/runtime/JsxDOM.res 2,663,743 2,639,446 -0.91%
packages/@rescript/runtime/Stdlib_Object.res 247,321 245,135 -0.88%
packages/@rescript/runtime/Stdlib_Pair.res 163,504 162,067 -0.88%
packages/@rescript/runtime/Dom_storage2.res 120,172 119,129 -0.87%
packages/@rescript/runtime/Stdlib_Null.res 327,687 324,843 -0.87%
packages/@rescript/runtime/Stdlib_Ordering.res 150,800 149,497 -0.86%
packages/@rescript/runtime/Stdlib_Result.res 1,244,123 1,233,379 -0.86%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,162 122,107 -0.86%
packages/@rescript/runtime/Primitive_string.res 157,486 156,152 -0.85%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,434 111,515 -0.82%
packages/@rescript/runtime/Primitive_object.resi 117,125 116,175 -0.81%
packages/@rescript/runtime/Primitive_float.res 145,080 143,920 -0.80%
packages/@rescript/belt/src/Belt_Result.res 403,540 400,318 -0.80%
packages/@rescript/runtime/Jsx.res 121,728 120,768 -0.79%
build/leaf-edit 12,585,959 12,487,828 -0.78%
packages/@rescript/belt/src/Belt_MapInt.res 1,157,536 1,148,590 -0.77%
packages/@rescript/belt/src/Belt_MapString.res 1,158,072 1,149,126 -0.77%
packages/@rescript/runtime/Stdlib_Iterator.res 233,092 231,319 -0.76%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 110,989 110,158 -0.75%
packages/@rescript/belt/src/Belt_Int.res 165,179 163,956 -0.74%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res 157,701 156,541 -0.74%
packages/@rescript/belt/src/Belt_Float.res 164,472 163,265 -0.73%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi 194,250 192,830 -0.73%
packages/@rescript/runtime/Primitive_option.resi 122,265 121,382 -0.72%
packages/@rescript/belt/src/Belt_internalBucketsType.res 288,380 286,301 -0.72%
packages/@rescript/runtime/Stdlib_AsyncIterator.res 291,832 289,737 -0.72%
packages/@rescript/runtime/Stdlib_Generator.res 198,756 197,351 -0.71%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res 209,566 208,099 -0.70%
packages/@rescript/belt/src/Belt.res 186,748 185,483 -0.68%
packages/@rescript/runtime/Stdlib_Temporal_Now.res 143,485 142,542 -0.66%
packages/@rescript/runtime/Primitive_object_extern.res 114,719 113,969 -0.65%
stress/RefsInLoop.res 16,263,243 16,157,281 -0.65%
packages/@rescript/runtime/Stdlib_Bool.res 144,639 143,698 -0.65%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 116,591 115,846 -0.64%
packages/@rescript/runtime/Stdlib_JsExn.res 171,547 170,456 -0.64%
packages/@rescript/runtime/Stdlib_IterableIterator.res 178,072 176,966 -0.62%
packages/@rescript/belt/src/Belt_internalBucketsType.resi 164,724 163,721 -0.61%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res 226,477 225,105 -0.61%
packages/@rescript/runtime/Primitive_bool.res 146,035 145,151 -0.61%
build/WideDeps/clean 369,418,350 367,201,618 -0.60%
packages/@rescript/runtime/Primitive_array_extern.res 114,210 113,537 -0.59%
packages/@rescript/runtime/Stdlib_Int8Array.res 343,389 341,615 -0.52%
packages/@rescript/runtime/Stdlib_Uint8Array.res 343,402 341,628 -0.52%
packages/@rescript/runtime/Stdlib_Float32Array.res 343,509 341,735 -0.52%
packages/@rescript/runtime/Stdlib_Float64Array.res 343,509 341,735 -0.52%
packages/@rescript/runtime/Stdlib_Int16Array.res 343,534 341,760 -0.52%
packages/@rescript/runtime/Stdlib_Int32Array.res 343,536 341,762 -0.52%
packages/@rescript/runtime/Stdlib_BigInt64Array.res 343,566 341,792 -0.52%
packages/@rescript/runtime/Stdlib_BigUint64Array.res 343,643 341,869 -0.52%
packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res 343,917 342,143 -0.52%
packages/@rescript/runtime/Stdlib_Uint16Array.res 343,541 341,769 -0.52%
packages/@rescript/runtime/Stdlib_Uint32Array.res 343,541 341,769 -0.52%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res 107,527 107,005 -0.49%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,124 105,657 -0.44%
packages/@rescript/runtime/Stdlib_Intl.res 173,152 172,395 -0.44%
packages/@rescript/runtime/Primitive_hash.resi 102,744 102,315 -0.42%
packages/@rescript/runtime/Primitive_module.resi 103,182 102,763 -0.41%
packages/@rescript/runtime/Primitive_exceptions.resi 100,319 99,922 -0.40%
packages/@rescript/runtime/Stdlib_Iterable.resi 98,169 97,822 -0.35%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi 98,318 97,971 -0.35%
stress/TypeAliasChain.res 2,361,456 2,353,232 -0.35%
build/WideDeps/edit 165,475,014 164,943,527 -0.32%
packages/@rescript/runtime/Primitive_dict.res 102,705 102,382 -0.31%
packages/@rescript/runtime/Stdlib.res 975,286 972,277 -0.31%
build/Namespace/clean 83,751,927 83,493,961 -0.31%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res 112,130 111,853 -0.25%
stress/ObjectFields.res 20,517,428 20,469,808 -0.23%
packages/@rescript/runtime/Primitive_string_extern.res 98,213 98,004 -0.21%
stress/Record.res 25,968,818 25,914,139 -0.21%
packages/@rescript/runtime/RescriptTools.res 104,367 104,155 -0.20%
packages/@rescript/runtime/Primitive_int_extern.res 97,905 97,709 -0.20%
packages/@rescript/runtime/Stdlib_Iterable.res 98,934 98,750 -0.19%
packages/@rescript/runtime/Stdlib_AsyncIterable.res 99,005 98,821 -0.19%
packages/@rescript/runtime/Primitive_promise.res 97,052 96,880 -0.18%
packages/@rescript/runtime/Stdlib_Temporal.res 223,253 222,910 -0.15%
packages/@rescript/runtime/Stdlib_File.res 95,704 95,557 -0.15%
stress/IntSwitch.res 29,600,928 29,558,829 -0.14%
packages/@rescript/runtime/Stdlib_Blob.res 93,895 93,764 -0.14%
packages/@rescript/runtime/Obj.res 99,154 99,020 -0.14%
stress/PolyVariantSwitch.res 14,207,950 14,190,579 -0.12%
packages/@rescript/runtime/Primitive_list.resi 91,887 91,777 -0.12%

Instructions

In total: 9,172,468,809 → 9,174,033,345 (+0.02%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,284,822 21,408,062 +0.58%
packages/@rescript/runtime/Stdlib_List.resi 24,512,081 24,653,828 +0.58%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,074,176 24,195,467 +0.50%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,514,116 25,633,025 +0.47%
packages/@rescript/runtime/Stdlib_String.resi 29,437,549 29,564,548 +0.43%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,181,842 31,313,408 +0.42%
packages/@rescript/belt/src/Belt_List.resi 38,970,842 39,115,015 +0.37%
packages/@rescript/belt/src/Belt_Array.resi 33,700,649 33,820,565 +0.36%
format/RedBlackTreeNoComments.res 24,068,051 24,141,060 +0.30%
format/RedBlackTree.res 24,413,059 24,486,068 +0.30%
10 more changes
Benchmark Base Head Change
parse/RedBlackTreeNoComments.res 14,485,551 14,527,221 +0.29%
parse/RedBlackTree.res 14,912,149 14,954,939 +0.29%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,295,440 41,409,738 +0.28%
parse/HeroGraphic.res 70,382,955 70,576,068 +0.27%
packages/@rescript/runtime/Stdlib_Array.resi 40,093,591 40,202,421 +0.27%
packages/@rescript/runtime/Stdlib_Date.resi 34,280,662 34,373,615 +0.27%
packages/@rescript/runtime/JsxDOMStyle.res 95,080,743 95,308,640 +0.24%
stress/ListLiteral.res 130,871,257 130,597,496 -0.21%
packages/@rescript/runtime/JsxDOM.res 117,100,261 117,241,329 +0.12%
parse/Napkinscript.res 333,229,897 332,832,475 -0.12%

Output size

In total: 25,963,868 → 25,965,258 (+0.01%).

Benchmark Base Head Change
output/playground/compiler.js 1,890,432 1,892,665 +0.12%

Pull request c4965ac compared with base 00a687b in this run.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.87500% with 81 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.19%. Comparing base (3d21237) to head (c4965ac).

Files with missing lines Patch % Lines
syntax/ast/ast_mapper.ml 88.52% 70 Missing ⚠️
compiler/frontend/bs_builtin_ppx.ml 88.23% 4 Missing ⚠️
tests/ounit_tests/ounit_ast_mapper_tests.ml 93.22% 4 Missing ⚠️
compiler/frontend/ast_tuple_pattern_flatten.ml 90.90% 2 Missing ⚠️
compiler/typing/ext_list.ml 94.73% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
compiler/frontend/jsx_ppx.ml 88.05% <ø> (-0.35%) ⬇️
tests/ounit_tests/ounit_list_test.ml 99.07% <100.00%> (+0.99%) ⬆️
tests/ounit_tests/ounit_tests_main.ml 100.00% <ø> (ø)
compiler/typing/ext_list.ml 89.33% <94.73%> (+0.36%) ⬆️
compiler/frontend/ast_tuple_pattern_flatten.ml 93.33% <90.90%> (-3.55%) ⬇️
compiler/frontend/bs_builtin_ppx.ml 89.96% <88.23%> (-0.53%) ⬇️
tests/ounit_tests/ounit_ast_mapper_tests.ml 93.22% <93.22%> (ø)
syntax/ast/ast_mapper.ml 89.58% <88.52%> (-10.42%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9395

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9395

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9395

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9395

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9395

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9395

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9395

commit: c4965ac

cknitt and others added 2 commits November 23, 2026 06:58
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>
@cknitt

cknitt commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T07:46:28.886902Z c4965ac Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: c4965ac249

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@cknitt
cknitt marked this pull request as ready for review November 23, 2026 08:51
@cknitt
cknitt removed this pull request from stack #9397 November 23, 2026 19:44
@cknitt

cknitt commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Closing together with #9394: no measurable build-time gain (same wall and CPU time over 20 clean builds of tests/tests, about 1% less peak memory), so the extra mapper code isn't worth it. The for-loop cleanup from the stack continues on its own in #9396.

@cknitt cknitt closed this Nov 23, 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.

2 participants