Skip to content

Share the variable-free parts of let-bound value types - #9300

Draft
cknitt wants to merge 1 commit into
masterfrom
share-closed-types-9265
Draft

cknitt wants to merge 1 commit into
masterfrom
share-closed-types-9265

Conversation

@cknitt

@cknitt cknitt commented Nov 14, 2026

Copy link
Copy Markdown
Member

Fixes the main part of #9265.

Every use of a let-bound value copied the value's whole type, including the parts without type variables. For a value with a large inferred object or polymorphic variant type, that made each use cost a full copy: in time, in memory, and in the .cmt. Saving the .cmi copied the type again for every signature item.

What changes

  • Ctype.generalize_value generalizes the type of a let-bound value, but leaves the parts without type variables non-generic at the let's level. copy keeps non-generic nodes, so all uses share these parts. OCaml already treats the parts of a weak type this way, so unification and later generalizations handle them as usual.
  • Subst.for_saving_signature, used only to save a .cmi, copies each such part once for the whole signature instead of once per item.

The shared parts can still be linked to equal types or have their level lowered, as weak types can. Their object fields' mutability can't be promoted: their rows are closed, and mutability cells are only merged together with their rows' tails. The comment on generalize_value explains this.

Not in this PR

  • Top-level values still pay about 1 ms per use for a 400-field type. The interface check copies each value's type twice (Subst.value_description in Includemod, and duplicate_type in moregeneral), and several callers rely on those copies to fix levels.
  • Values from other modules (types loaded from a .cmi) are still copied at each use.

Numbers (linux-arm64, master vs this PR, identical JS)

case master PR
stress/ObjectFields.res: time 192 ms 38 ms
stress/ObjectFields.res: allocated words 20.7M 3.9M
stress/ObjectFields.res: .cmt 7.98 MB 207 KB
400-field object, 400 top-level uses: .cmt / .cmi 8.85 MB / 8.9 MB 114 KB / 37 KB
same 400 uses inside a function: time 271 ms 47 ms

Tests

tests/tests/src/shared_variable_free_types.res uses values with variable-free object and variant types through open objects, settable fields, recursion, GADT branches and a weak ref.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gLMbg8G3FeSq6sPLM2

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Changelog

💅 Polish

  • Compile values with large object or polymorphic variant types faster and write much smaller .cmt and .cmi files for them, by sharing the parts of their types that contain no type variable instead of copying them at every use.

Semantic Diff

1 commit · Full page

Share the variable-free parts of let-bound value types

8abb139 · cknitt + Claude · Nov 14, 2026, 08:37 UTC

Why

Every use of a let-bound value copied its whole type, even the parts without type variables. For a value with a 400-field object type, each use added about 22 KB to the .cmt, and saving the .cmi copied the type again for every signature item (#9265).

The parts of a let-bound value's type that contain no type variable now stay non-generic at the binding's level, like the parts of a weak type. Instantiation keeps non-generic nodes, so all uses share them. Saving a signature copies each such part once for the whole .cmi, reusing a copy only under the path substitution it was made with. Generic nodes never count as variable-free, so a shared part never contains one.

Typing: Ctype.generalize_value (let-bound patterns)

let o = {"f0": 0, /* … 400 fields */}
let g0 = o
let g1 = o

text

-generalize o's type: every node generic, each use copies all 400 fields
+generalize o's type: variable-free nodes stay at the let's level, each use shares them

Review

  • Can a shared part change after it is shared? Unification may link it to an equal type or lower its level, as for weak types. The mutability cells of its object fields can't be promoted: its rows are closed, and cells are merged only together with their rows' tails.

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.37864% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.27%. Comparing base (643e9c0) to head (8abb139).

Files with missing lines Patch % Lines
compiler/typing/subst.ml 83.56% 12 Missing ⚠️
compiler/typing/ctype.ml 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9300      +/-   ##
==========================================
+ Coverage   82.21%   82.27%   +0.06%     
==========================================
  Files         460      460              
  Lines       65551    65609      +58     
==========================================
+ Hits        53891    53980      +89     
+ Misses      11660    11629      -31     
Files with missing lines Coverage Δ
compiler/typing/env.ml 81.00% <100.00%> (ø)
compiler/typing/typecore.ml 89.12% <100.00%> (ø)
compiler/typing/ctype.ml 72.06% <96.42%> (+1.63%) ⬆️
compiler/typing/subst.ml 88.05% <83.56%> (+2.09%) ⬆️

... and 1 file with indirect coverage changes

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

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

⚠️ Compiler benchmarks

Allocated words

In total: 636,509,557 → 623,049,606 (-2.11%).

Generated projects: 629,030,485 → 631,025,666 (+0.32%).

⚠️ Regression: 67 benchmarks allocate more than 1% more.

🎉 Improvement: 2 benchmarks allocate more than 1% less.

Benchmark Base Head Change
stress/ObjectFields.res 20,649,523 3,774,534 -81.72%
stress/Record.res 26,115,923 28,839,840 +10.43%
packages/@rescript/runtime/JsxEvent.res 1,090,874 1,123,058 +2.95%
packages/@rescript/runtime/Stdlib_Int8Array.res 343,494 352,295 +2.56%
packages/@rescript/runtime/Stdlib_Uint8Array.res 343,507 352,308 +2.56%
packages/@rescript/runtime/Stdlib_Float32Array.res 343,614 352,415 +2.56%
packages/@rescript/runtime/Stdlib_Float64Array.res 343,614 352,415 +2.56%
packages/@rescript/runtime/Stdlib_Int16Array.res 343,639 352,440 +2.56%
packages/@rescript/runtime/Stdlib_Int32Array.res 343,641 352,442 +2.56%
packages/@rescript/runtime/Stdlib_Uint16Array.res 343,646 352,447 +2.56%
230 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Uint32Array.res 343,646 352,447 +2.56%
packages/@rescript/runtime/Stdlib_BigInt64Array.res 343,671 352,472 +2.56%
packages/@rescript/runtime/Stdlib_BigUint64Array.res 343,748 352,549 +2.56%
packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res 344,022 352,823 +2.56%
packages/@rescript/belt/src/Belt_MutableSetString.resi 264,996 270,777 +2.18%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 265,113 270,894 +2.18%
packages/@rescript/belt/src/Belt_SetString.resi 259,922 265,384 +2.10%
packages/@rescript/belt/src/Belt_SetInt.resi 260,049 265,511 +2.10%
stress/InlineChain.res 3,511,206 3,443,483 -1.93%
packages/@rescript/runtime/Stdlib_String.resi 497,477 507,066 +1.93%
packages/@rescript/runtime/Stdlib_DataView.resi 268,044 273,001 +1.85%
packages/@rescript/runtime/Stdlib_Date.resi 614,248 625,470 +1.83%
packages/@rescript/runtime/JsxDOM.res 2,663,753 2,711,115 +1.78%
packages/@rescript/runtime/Stdlib_TypedArray.res 785,351 798,233 +1.64%
packages/@rescript/runtime/Stdlib_Math.resi 328,324 333,549 +1.59%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 574,181 582,957 +1.53%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res 404,810 410,917 +1.51%
packages/@rescript/runtime/JsxDOMStyle.res 1,935,499 1,964,027 +1.47%
packages/@rescript/runtime/Stdlib_BigInt.resi 186,569 189,291 +1.46%
packages/@rescript/runtime/Stdlib_Int.resi 206,103 209,076 +1.44%
packages/@rescript/belt/src/Belt_MapString.resi 391,308 396,922 +1.43%
packages/@rescript/belt/src/Belt_MapInt.resi 391,351 396,965 +1.43%
packages/@rescript/belt/src/Belt_Range.resi 176,657 179,171 +1.42%
packages/@rescript/belt/src/Belt_MutableMapString.resi 314,993 319,395 +1.40%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 315,111 319,513 +1.40%
packages/@rescript/runtime/Stdlib_JSON.resi 237,027 240,240 +1.36%
packages/@rescript/belt/src/Belt_Array.resi 650,336 658,916 +1.32%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,553 177,865 +1.32%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,666 177,978 +1.32%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,577 171,795 +1.31%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,695 171,913 +1.31%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res 389,599 394,595 +1.28%
packages/@rescript/runtime/Stdlib_Float.resi 194,292 196,730 +1.25%
packages/@rescript/runtime/Stdlib_Intl_Locale.res 198,068 200,493 +1.22%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 438,194 443,551 +1.22%
packages/@rescript/runtime/Stdlib_Array.resi 728,603 737,436 +1.21%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res 201,889 204,328 +1.21%
packages/@rescript/belt/src/Belt_SortArray.resi 253,942 256,972 +1.19%
packages/@rescript/runtime/Pervasives.res 239,805 242,657 +1.19%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,800 190,012 +1.18%
packages/@rescript/runtime/Stdlib_Global.resi 155,548 157,350 +1.16%
packages/@rescript/runtime/Stdlib_List.resi 409,863 414,601 +1.16%
packages/@rescript/belt/src/Belt_List.resi 758,744 767,509 +1.16%
packages/@rescript/belt/src/Belt_HashMapString.resi 213,714 216,154 +1.14%
packages/@rescript/belt/src/Belt_HashMapInt.resi 213,828 216,268 +1.14%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res 373,600 377,821 +1.13%
packages/@rescript/runtime/Stdlib_Intl_Collator.res 178,667 180,652 +1.11%
packages/@rescript/runtime/RescriptTools_Docgen.resi 273,524 276,555 +1.11%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res 180,464 182,454 +1.10%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 403,907 408,341 +1.10%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res 169,825 171,684 +1.09%
packages/@rescript/runtime/Primitive_object.resi 117,125 118,400 +1.09%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res 382,285 386,443 +1.09%
packages/@rescript/runtime/Stdlib_JsError.resi 184,968 186,960 +1.08%
packages/@rescript/runtime/Dom_storage2.res 120,182 121,461 +1.06%
packages/@rescript/belt/src/Belt_internalAVLset.resi 354,869 358,596 +1.05%
packages/@rescript/belt/src/Belt_Id.resi 260,286 262,959 +1.03%
packages/@rescript/runtime/Stdlib_Promise.resi 356,017 359,668 +1.03%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,775 124,034 +1.03%
packages/@rescript/runtime/Stdlib_Bool.resi 116,818 117,975 +0.99%
packages/@rescript/belt/src/Belt_Range.res 288,346 285,497 -0.99%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res 154,540 156,049 +0.98%
packages/@rescript/runtime/Stdlib_Option.resi 236,507 238,806 +0.97%
packages/@rescript/runtime/Primitive_hash.resi 102,744 103,742 +0.97%
build/leaf-edit 13,027,605 12,901,183 -0.97%
packages/@rescript/belt/src/Belt_internalAVLtree.resi 452,423 456,775 +0.96%
packages/@rescript/belt/src/Belt_MutableMap.resi 395,444 399,245 +0.96%
packages/@rescript/belt/src/Belt_MapDict.resi 513,298 518,224 +0.96%
packages/@rescript/runtime/Stdlib_Dict.resi 240,779 243,066 +0.95%
packages/@rescript/runtime/Jsx.res 121,738 122,885 +0.94%
packages/@rescript/runtime/Stdlib_Console.resi 411,610 415,467 +0.94%
packages/@rescript/belt/src/Belt_Int.resi 149,771 151,164 +0.93%
packages/@rescript/runtime/Primitive_object_extern.res 114,729 115,795 +0.93%
packages/@rescript/belt/src/Belt_Float.resi 151,251 152,644 +0.92%
packages/@rescript/belt/src/Belt_MutableSet.resi 397,546 401,206 +0.92%
packages/@rescript/runtime/Primitive_module.resi 103,182 104,130 +0.92%
packages/@rescript/runtime/Stdlib_Result.resi 296,377 299,095 +0.92%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 110,989 112,001 +0.91%
packages/@rescript/runtime/Stdlib_Symbol.resi 160,141 161,573 +0.89%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,281 170,789 +0.89%
packages/@rescript/runtime/Primitive_option.resi 122,265 123,354 +0.89%
packages/@rescript/belt/src/Belt_Option.resi 243,374 245,518 +0.88%
build/Namespace/clean 84,163,048 84,900,979 +0.88%
packages/@rescript/belt/src/Belt_MutableQueue.resi 207,326 209,126 +0.87%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 234,376 236,407 +0.87%
packages/@rescript/belt/src/Belt_SetDict.resi 402,680 406,086 +0.85%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 116,601 117,584 +0.84%
packages/@rescript/runtime/Primitive_array_extern.res 114,220 115,181 +0.84%
packages/@rescript/belt/src/Belt_Map.resi 579,471 584,310 +0.84%
packages/@rescript/runtime/Primitive_exceptions.resi 100,319 101,156 +0.83%
packages/@rescript/runtime/Primitive_int_extern.res 97,915 98,729 +0.83%
packages/@rescript/belt/src/Belt_Set.resi 437,438 441,071 +0.83%
packages/@rescript/runtime/Stdlib_Set.resi 228,953 230,852 +0.83%
packages/@rescript/runtime/Primitive_string_extern.res 98,223 99,037 +0.83%
packages/@rescript/runtime/Stdlib_Map.resi 217,108 218,896 +0.82%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res 320,257 322,881 +0.82%
packages/@rescript/runtime/Stdlib_JsExn.res 173,080 171,685 -0.81%
packages/@rescript/belt/src/Belt_HashSet.resi 222,778 224,543 +0.79%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 177,818 179,208 +0.78%
packages/@rescript/runtime/Primitive_dict.res 102,715 103,507 +0.77%
packages/@rescript/runtime/Stdlib_Nullable.resi 199,672 201,196 +0.76%
packages/@rescript/runtime/Stdlib_Object.res 247,331 249,205 +0.76%
packages/@rescript/runtime/Primitive_list.resi 91,887 92,569 +0.74%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,434 113,268 +0.74%
packages/@rescript/runtime/Primitive_float_extern.res 93,687 94,378 +0.74%
packages/@rescript/runtime/Stdlib_Null.resi 204,431 205,933 +0.73%
packages/@rescript/runtime/Stdlib_Type.resi 135,946 136,943 +0.73%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,925 161,097 +0.73%
packages/@rescript/runtime/Stdlib_Iterator.resi 159,246 160,412 +0.73%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,172 124,061 +0.72%
packages/@rescript/belt/src/Belt_HashMap.resi 296,908 299,041 +0.72%
packages/@rescript/belt/src/Belt_Result.resi 240,168 241,880 +0.71%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res 307,599 309,785 +0.71%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,406 150,465 +0.71%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,124 106,873 +0.71%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res 112,140 112,931 +0.71%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res 159,421 160,543 +0.70%
packages/@rescript/runtime/Stdlib_Iterable.resi 98,169 98,859 +0.70%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi 98,318 99,008 +0.70%
packages/@rescript/runtime/Primitive_promise.res 97,062 97,742 +0.70%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,503 136,439 +0.69%
packages/@rescript/runtime/Stdlib_Ordering.res 152,340 153,377 +0.68%
build/no-op 9,213,678 9,151,409 -0.68%
packages/@rescript/runtime/Stdlib_File.res 95,714 96,359 +0.67%
packages/@rescript/runtime/Obj.res 99,164 99,824 +0.67%
packages/@rescript/runtime/Stdlib_Pair.res 165,262 166,361 +0.67%
packages/@rescript/runtime/Dom.res 1,071,712 1,078,825 +0.66%
packages/@rescript/runtime/Stdlib_Blob.res 93,905 94,525 +0.66%
packages/@rescript/belt/src/Belt_MutableSetString.res 1,665,801 1,654,843 -0.66%
packages/@rescript/belt/src/Belt_MutableSetInt.res 1,664,555 1,653,609 -0.66%
packages/@rescript/belt/src/Belt_internalBuckets.resi 223,042 224,494 +0.65%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi 194,250 195,512 +0.65%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,925 166,995 +0.64%
packages/@rescript/belt/src/Belt_internalBucketsType.resi 164,724 165,769 +0.63%
packages/@rescript/runtime/Stdlib_Intl_Common.res 154,360 155,338 +0.63%
packages/@rescript/runtime/Stdlib_Iterable.res 98,944 99,563 +0.63%
packages/@rescript/runtime/Stdlib_AsyncIterable.res 99,015 99,634 +0.63%
packages/@rescript/runtime/Dom_storage.res 167,042 168,083 +0.62%
packages/@rescript/runtime/Stdlib_Generator.resi 160,547 161,545 +0.62%
packages/@rescript/runtime/RescriptTools.res 104,517 105,162 +0.62%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res 107,537 108,156 +0.58%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res 268,246 269,785 +0.57%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res 115,368 116,023 +0.57%
packages/@rescript/runtime/Stdlib_Iterator.res 234,922 236,241 +0.56%
packages/@rescript/runtime/Primitive_object.res 1,154,866 1,148,508 -0.55%
packages/@rescript/runtime/Stdlib_Intl.res 173,862 174,819 +0.55%
packages/@rescript/runtime/Primitive_bool.res 147,218 147,994 +0.53%
packages/@rescript/runtime/Primitive_float.res 146,893 147,667 +0.53%
packages/@rescript/runtime/Primitive_array.res 191,984 192,980 +0.52%
packages/@rescript/runtime/Primitive_string.res 159,592 160,419 +0.52%
packages/@rescript/runtime/Primitive_int.res 171,842 172,720 +0.51%
packages/@rescript/runtime/Stdlib_IterableIterator.res 178,852 179,740 +0.50%
packages/@rescript/runtime/Primitive_bigint.res 177,314 178,192 +0.50%
packages/@rescript/runtime/Stdlib_Lazy.res 221,184 222,273 +0.49%
packages/@rescript/runtime/Stdlib_AsyncIterator.res 294,756 296,198 +0.49%
packages/@rescript/runtime/Primitive_list.res 203,745 204,695 +0.47%
packages/@rescript/runtime/Stdlib_Global.res 141,743 142,368 +0.44%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res 211,156 212,082 +0.44%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res 228,325 229,322 +0.44%
packages/@rescript/belt/src/Belt_Option.res 389,121 390,813 +0.43%
packages/@rescript/runtime/Stdlib_Generator.res 200,286 201,152 +0.43%
stress/LetRec.res 31,619,781 31,753,548 +0.42%
packages/@rescript/runtime/Stdlib_Symbol.res 146,511 147,130 +0.42%
packages/@rescript/belt/src/Belt_Map.res 981,236 985,325 +0.42%
packages/@rescript/belt/src/Belt_Set.res 857,946 861,388 +0.40%
packages/@rescript/runtime/Stdlib_JsError.res 229,751 230,672 +0.40%
packages/@rescript/runtime/Primitive_exceptions.res 201,232 202,031 +0.40%
packages/@rescript/runtime/Stdlib_Null.res 332,359 333,672 +0.40%
packages/@rescript/runtime/Stdlib_Nullable.res 329,857 331,155 +0.39%
packages/@rescript/runtime/Primitive_js_extern.res 239,834 240,773 +0.39%
packages/@rescript/belt/src/Belt_Float.res 165,048 165,688 +0.39%
packages/@rescript/belt/src/Belt_Result.res 409,437 411,023 +0.39%
packages/@rescript/belt/src/Belt_Int.res 165,790 166,430 +0.39%
packages/@rescript/belt/src/Belt.res 187,948 188,666 +0.38%
packages/@rescript/runtime/Stdlib_RegExp.res 163,713 164,337 +0.38%
packages/@rescript/runtime/Stdlib_Dict.res 320,111 321,329 +0.38%
packages/@rescript/belt/src/Belt_SortArrayInt.res 1,342,429 1,337,388 -0.38%
packages/@rescript/belt/src/Belt_SortArrayString.res 1,344,225 1,339,183 -0.38%
packages/@rescript/runtime/Stdlib_Bool.res 146,012 146,545 +0.37%
packages/@rescript/belt/src/Belt_MapDict.res 1,630,823 1,636,337 +0.34%
packages/@rescript/belt/src/Belt_Id.res 289,887 290,844 +0.33%
packages/@rescript/runtime/Stdlib_Type.res 201,438 202,100 +0.33%
packages/@rescript/runtime/Stdlib_Map.res 205,648 206,313 +0.32%
packages/@rescript/runtime/Stdlib_Set.res 210,990 211,656 +0.32%
packages/@rescript/belt/src/Belt_MutableQueue.res 791,334 793,755 +0.31%
packages/@rescript/belt/src/Belt_SetDict.res 1,445,985 1,450,392 +0.30%
packages/@rescript/runtime/Stdlib_IteratorObject.res 250,722 251,474 +0.30%
packages/@rescript/belt/src/Belt_internalBucketsType.res 291,615 292,482 +0.30%
build/shared-edit 72,589,408 72,377,984 -0.29%
packages/@rescript/runtime/Stdlib_Option.res 753,633 755,828 +0.29%
packages/@rescript/runtime/Stdlib_Temporal_Now.res 143,495 143,909 +0.29%
packages/@rescript/runtime/Stdlib_Float.res 218,863 219,457 +0.27%
packages/@rescript/runtime/Stdlib_DataView.res 230,306 230,926 +0.27%
packages/@rescript/belt/src/Belt_MutableStack.res 387,514 388,556 +0.27%
packages/@rescript/belt/src/Belt_MutableMap.res 1,302,290 1,305,767 +0.27%
packages/@rescript/belt/src/Belt_internalSetBuckets.res 699,079 700,908 +0.26%
packages/@rescript/belt/src/Belt_internalBuckets.res 966,624 969,103 +0.26%
build/WideDeps/clean 371,070,932 372,011,357 +0.25%
packages/@rescript/runtime/Stdlib_Temporal_Common.res 366,668 367,584 +0.25%
packages/@rescript/belt/src/Belt_MutableSet.res 1,902,475 1,907,206 +0.25%
packages/@rescript/belt/src/Belt_internalMapInt.res 1,408,499 1,411,983 +0.25%
packages/@rescript/belt/src/Belt_internalMapString.res 1,410,343 1,413,831 +0.25%
packages/@rescript/runtime/Stdlib_BigInt.res 207,074 207,585 +0.25%
packages/@rescript/runtime/Stdlib_Array.res 1,281,101 1,284,178 +0.24%
packages/@rescript/runtime/Stdlib.res 980,476 982,706 +0.23%
packages/@rescript/runtime/RescriptTools_Docgen.res 283,791 284,432 +0.23%
packages/@rescript/belt/src/Belt_HashSet.res 978,208 980,404 +0.22%
packages/@rescript/belt/src/Belt_HashSetString.res 850,837 848,928 -0.22%
packages/@rescript/belt/src/Belt_HashSetInt.res 850,520 848,612 -0.22%
packages/@rescript/belt/src/Belt_MapInt.res 1,181,363 1,183,938 +0.22%
packages/@rescript/belt/src/Belt_MapString.res 1,181,899 1,184,474 +0.22%
packages/@rescript/belt/src/Belt_internalAVLtree.res 3,506,403 3,513,991 +0.22%
packages/@rescript/runtime/Stdlib_Result.res 1,268,255 1,270,982 +0.22%
packages/@rescript/runtime/Stdlib_List.res 2,686,422 2,692,022 +0.21%
packages/@rescript/runtime/Primitive_hash.res 964,614 962,658 -0.20%
packages/@rescript/belt/src/Belt_List.res 3,175,359 3,181,673 +0.20%
packages/@rescript/runtime/Stdlib_Promise.res 352,778 353,476 +0.20%
packages/@rescript/belt/src/Belt_Array.res 2,154,235 2,158,460 +0.20%
build/WideDeps/edit 165,920,746 166,230,466 +0.19%
packages/@rescript/runtime/Stdlib_Console.res 370,179 370,831 +0.18%
build/clean 236,610,459 236,995,790 +0.16%
packages/@rescript/runtime/Stdlib_Math.res 327,556 328,074 +0.16%
packages/@rescript/belt/src/Belt_HashMap.res 1,200,049 1,201,915 +0.16%
packages/@rescript/runtime/Stdlib_JSON.res 296,903 297,357 +0.15%
packages/@rescript/runtime/Stdlib_Int.res 455,336 456,016 +0.15%
packages/@rescript/belt/src/Belt_internalAVLset.res 2,876,034 2,879,552 +0.12%
packages/@rescript/belt/src/Belt_HashMapInt.res 1,060,707 1,061,923 +0.11%
packages/@rescript/belt/src/Belt_HashMapString.res 1,061,419 1,062,632 +0.11%
packages/@rescript/belt/src/Belt_internalSetInt.res 730,723 729,974 -0.10%
packages/@rescript/belt/src/Belt_internalSetString.res 731,914 731,166 -0.10%

Instructions

In total: 9,221,430,898 → 8,607,495,003 (-6.66%).

⚠️ Regression: 15 benchmarks execute more than 1% more instructions.

🎉 Improvement: 2 benchmarks execute more than 1% fewer instructions.

Benchmark Base Head Change
stress/ObjectFields.res 945,446,739 189,304,912 -79.98%
stress/Record.res 1,072,160,021 1,186,745,523 +10.69%
packages/@rescript/runtime/JsxDOM.res 117,111,700 120,095,043 +2.55%
packages/@rescript/runtime/Stdlib_String.resi 29,450,187 30,046,508 +2.02%
packages/@rescript/runtime/JsxDOMStyle.res 95,092,558 96,921,399 +1.92%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,307,639 42,093,434 +1.90%
packages/@rescript/runtime/Stdlib_Date.resi 34,293,759 34,943,868 +1.90%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,194,337 31,732,775 +1.73%
packages/@rescript/belt/src/Belt_Array.resi 33,711,204 34,251,068 +1.60%
stress/InlineChain.res 138,210,645 136,038,145 -1.57%
14 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,296,459 21,604,560 +1.45%
stress/LetRec.res 1,377,895,324 1,397,673,178 +1.44%
packages/@rescript/belt/src/Belt_List.resi 38,983,079 39,538,053 +1.42%
packages/@rescript/runtime/Stdlib_Array.resi 40,104,330 40,640,115 +1.34%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,526,630 25,834,517 +1.21%
packages/@rescript/runtime/Stdlib_List.resi 24,523,891 24,816,298 +1.19%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,086,816 24,341,871 +1.06%
stress/TypeAliasChain.res 171,851,520 171,066,001 -0.46%
packages/@rescript/belt/src/Belt_List.res 118,135,150 118,382,728 +0.21%
parse/RedBlackTreeNoComments.res 14,487,527 14,517,064 +0.20%
parse/RedBlackTree.res 14,919,508 14,944,359 +0.17%
packages/@rescript/belt/src/Belt_internalAVLtree.res 136,419,478 136,567,514 +0.11%
format/RedBlackTreeNoComments.res 24,073,608 24,098,536 +0.10%
format/RedBlackTree.res 24,418,540 24,443,468 +0.10%

Output size

In total: 25,962,507 → 25,743,616 (-0.84%).

🎉 Improvement: 2 outputs are more than 1% smaller.

Benchmark Base Head Change
output/tests/*.cmt 11,125,783 10,964,777 -1.45%
output/belt/*.cmt 2,752,575 2,713,655 -1.41%
output/tests/*.cmi 2,356,307 2,343,195 -0.56%
output/runtime/*.cmt 3,035,969 3,029,818 -0.20%

Pull request 8abb139 compared with base 643e9c0 in this run.

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 8abb139

@cknitt
cknitt force-pushed the share-closed-types-9265 branch from 33709fb to 8541c8e Compare November 20, 2026 21:10
Why:
    Every use of a let-bound value copied its whole type, even the parts
    without type variables. For a value with a 400-field object type,
    each use added about 22 KB to the .cmt, and saving the .cmi copied the
    type again for every signature item (#9265).

The parts of a let-bound value's type that contain no type variable now
stay non-generic at the binding's level, like the parts of a weak type.
Instantiation keeps non-generic nodes, so all uses share them. Saving a
signature copies each such part once for the whole .cmi, reusing a copy
only under the path substitution it was made with. Generic nodes never
count as variable-free, so a shared part never contains one.

Typing: Ctype.generalize_value (let-bound patterns)
    let o = {"f0": 0, /* … 400 fields */}
    let g0 = o
    let g1 = o
Before (text): generalize o's type: every node generic, each use copies all 400 fields
After (text): generalize o's type: variable-free nodes stay at the let's level, each use shares them

Review: Can a shared part change after it is shared? Unification may link
it to an equal type or lower its level, as for weak types. The mutability
cells of its object fields can't be promoted: its rows are closed, and
cells are merged only together with their rows' tails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMbg8G3FeSq6sPLM2
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the share-closed-types-9265 branch from 8541c8e to 8abb139 Compare November 23, 2026 06:47

This branch has not been deployed

No deployments
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