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

8541c8e · 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.23%. Comparing base (a826170) to head (8541c8e).

Files with missing lines Patch % Lines
compiler/ml/subst.ml 83.56% 12 Missing ⚠️
compiler/ml/ctype.ml 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9300      +/-   ##
==========================================
+ Coverage   82.17%   82.23%   +0.06%     
==========================================
  Files         458      458              
  Lines       65678    65736      +58     
==========================================
+ Hits        53971    54060      +89     
+ Misses      11707    11676      -31     
Files with missing lines Coverage Δ
compiler/ml/env.ml 81.00% <100.00%> (ø)
compiler/ml/typecore.ml 89.15% <100.00%> (ø)
compiler/ml/ctype.ml 72.22% <96.42%> (+1.64%) ⬆️
compiler/ml/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: 639,870,140 → 626,417,242 (-2.10%).

Generated projects: 629,807,062 → 631,800,512 (+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,693,027 3,818,038 -81.55%
stress/Record.res 26,163,227 28,887,144 +10.41%
packages/@rescript/runtime/JsxEvent.res 1,091,825 1,124,561 +3.00%
packages/@rescript/runtime/Stdlib_Int8Array.res 343,403 352,204 +2.56%
packages/@rescript/runtime/Stdlib_Uint8Array.res 343,416 352,217 +2.56%
packages/@rescript/runtime/Stdlib_Float32Array.res 343,523 352,324 +2.56%
packages/@rescript/runtime/Stdlib_Float64Array.res 343,523 352,324 +2.56%
packages/@rescript/runtime/Stdlib_Int16Array.res 343,548 352,349 +2.56%
packages/@rescript/runtime/Stdlib_Int32Array.res 343,550 352,351 +2.56%
packages/@rescript/runtime/Stdlib_Uint16Array.res 343,555 352,356 +2.56%
230 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Uint32Array.res 343,555 352,356 +2.56%
packages/@rescript/runtime/Stdlib_BigInt64Array.res 343,580 352,381 +2.56%
packages/@rescript/runtime/Stdlib_BigUint64Array.res 343,657 352,458 +2.56%
packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res 343,931 352,732 +2.56%
packages/@rescript/belt/src/Belt_MutableSetString.resi 264,910 270,691 +2.18%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 265,027 270,808 +2.18%
packages/@rescript/belt/src/Belt_SetString.resi 259,836 265,298 +2.10%
packages/@rescript/belt/src/Belt_SetInt.resi 259,963 265,425 +2.10%
packages/@rescript/runtime/Stdlib_String.resi 497,419 507,008 +1.93%
stress/InlineChain.res 3,586,563 3,518,840 -1.89%
packages/@rescript/runtime/Stdlib_DataView.resi 267,958 272,915 +1.85%
packages/@rescript/runtime/Stdlib_Date.resi 614,211 625,433 +1.83%
packages/@rescript/runtime/JsxDOM.res 2,663,572 2,710,934 +1.78%
packages/@rescript/runtime/Stdlib_TypedArray.res 785,231 798,113 +1.64%
packages/@rescript/runtime/Stdlib_Math.resi 328,609 333,834 +1.59%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 574,641 583,417 +1.53%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res 404,689 410,796 +1.51%
packages/@rescript/runtime/JsxDOMStyle.res 1,935,330 1,963,858 +1.47%
packages/@rescript/runtime/Stdlib_BigInt.resi 186,497 189,219 +1.46%
packages/@rescript/runtime/Stdlib_Int.resi 206,017 208,990 +1.44%
packages/@rescript/belt/src/Belt_MapString.resi 391,222 396,836 +1.43%
packages/@rescript/belt/src/Belt_MapInt.resi 391,265 396,879 +1.43%
packages/@rescript/belt/src/Belt_Range.resi 176,571 179,085 +1.42%
packages/@rescript/belt/src/Belt_MutableMapString.resi 314,907 319,309 +1.40%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 315,025 319,427 +1.40%
packages/@rescript/runtime/Stdlib_JSON.resi 237,034 240,247 +1.36%
packages/@rescript/belt/src/Belt_Array.resi 650,246 658,826 +1.32%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,467 177,779 +1.32%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,580 177,892 +1.32%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,491 171,709 +1.31%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,609 171,827 +1.31%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res 389,444 394,440 +1.28%
packages/@rescript/runtime/Stdlib_Float.resi 194,241 196,679 +1.26%
packages/@rescript/runtime/Stdlib_Intl_Locale.res 197,906 200,331 +1.23%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 438,634 443,991 +1.22%
packages/@rescript/runtime/Stdlib_Array.resi 728,548 737,381 +1.21%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res 201,734 204,173 +1.21%
packages/@rescript/belt/src/Belt_SortArray.resi 253,856 256,886 +1.19%
packages/@rescript/runtime/Pervasives.res 239,636 242,488 +1.19%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,713 189,925 +1.18%
packages/@rescript/runtime/Stdlib_Global.resi 155,462 157,264 +1.16%
packages/@rescript/runtime/Stdlib_List.resi 409,777 414,515 +1.16%
packages/@rescript/belt/src/Belt_List.resi 758,658 767,423 +1.16%
packages/@rescript/belt/src/Belt_HashMapString.resi 213,628 216,068 +1.14%
packages/@rescript/belt/src/Belt_HashMapInt.resi 213,742 216,182 +1.14%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res 374,026 378,247 +1.13%
packages/@rescript/runtime/Stdlib_Intl_Collator.res 178,512 180,497 +1.11%
packages/@rescript/runtime/RescriptTools_Docgen.resi 273,494 276,525 +1.11%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res 180,309 182,299 +1.10%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 404,326 408,760 +1.10%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res 169,670 171,529 +1.10%
packages/@rescript/runtime/Primitive_object.resi 117,039 118,314 +1.09%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res 382,716 386,874 +1.09%
packages/@rescript/runtime/Stdlib_JsError.resi 184,882 186,874 +1.08%
packages/@rescript/runtime/Dom_storage2.res 120,013 121,292 +1.07%
packages/@rescript/belt/src/Belt_internalAVLset.resi 354,783 358,510 +1.05%
packages/@rescript/belt/src/Belt_Id.resi 260,200 262,873 +1.03%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,689 123,948 +1.03%
packages/@rescript/runtime/Stdlib_Promise.resi 355,939 359,590 +1.03%
packages/@rescript/runtime/Stdlib_Bool.resi 116,732 117,889 +0.99%
packages/@rescript/belt/src/Belt_Range.res 290,478 287,629 -0.98%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res 154,385 155,894 +0.98%
packages/@rescript/runtime/Stdlib_Option.resi 236,417 238,716 +0.97%
packages/@rescript/runtime/Primitive_hash.resi 102,658 103,656 +0.97%
packages/@rescript/belt/src/Belt_internalAVLtree.resi 452,337 456,689 +0.96%
packages/@rescript/belt/src/Belt_MutableMap.resi 395,358 399,159 +0.96%
packages/@rescript/belt/src/Belt_MapDict.resi 513,212 518,138 +0.96%
build/leaf-edit 13,214,906 13,088,478 -0.96%
packages/@rescript/runtime/Stdlib_Dict.resi 240,762 243,049 +0.95%
packages/@rescript/runtime/Jsx.res 121,569 122,716 +0.94%
packages/@rescript/runtime/Stdlib_Console.resi 411,909 415,766 +0.94%
packages/@rescript/belt/src/Belt_Int.resi 149,685 151,078 +0.93%
packages/@rescript/runtime/Primitive_object_extern.res 114,560 115,626 +0.93%
packages/@rescript/belt/src/Belt_Float.resi 151,165 152,558 +0.92%
packages/@rescript/belt/src/Belt_MutableSet.resi 397,460 401,120 +0.92%
packages/@rescript/runtime/Primitive_module.resi 103,096 104,044 +0.92%
packages/@rescript/runtime/Stdlib_Result.resi 296,287 299,005 +0.92%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 110,903 111,915 +0.91%
packages/@rescript/runtime/Stdlib_Symbol.resi 160,055 161,487 +0.89%
packages/@rescript/runtime/Primitive_option.resi 122,179 123,268 +0.89%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,195 170,703 +0.89%
packages/@rescript/belt/src/Belt_Option.resi 243,288 245,432 +0.88%
build/Namespace/clean 84,216,074 84,953,798 +0.88%
packages/@rescript/belt/src/Belt_MutableQueue.resi 207,240 209,040 +0.87%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 234,297 236,328 +0.87%
packages/@rescript/belt/src/Belt_SetDict.resi 402,594 406,000 +0.85%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 116,432 117,415 +0.84%
packages/@rescript/runtime/Primitive_array_extern.res 114,051 115,012 +0.84%
packages/@rescript/belt/src/Belt_Map.resi 579,385 584,224 +0.84%
packages/@rescript/runtime/Primitive_exceptions.resi 100,233 101,070 +0.84%
packages/@rescript/runtime/Primitive_int_extern.res 97,746 98,560 +0.83%
packages/@rescript/belt/src/Belt_Set.resi 437,352 440,985 +0.83%
packages/@rescript/runtime/Primitive_string_extern.res 98,054 98,868 +0.83%
packages/@rescript/runtime/Stdlib_Set.resi 228,874 230,773 +0.83%
packages/@rescript/runtime/Stdlib_Map.resi 217,022 218,810 +0.82%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res 320,676 323,300 +0.82%
packages/@rescript/runtime/Stdlib_JsExn.res 173,528 172,133 -0.80%
packages/@rescript/belt/src/Belt_HashSet.resi 222,692 224,457 +0.79%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 177,732 179,122 +0.78%
packages/@rescript/runtime/Primitive_dict.res 102,553 103,345 +0.77%
packages/@rescript/runtime/Stdlib_Nullable.resi 199,756 201,280 +0.76%
packages/@rescript/runtime/Stdlib_Object.res 247,268 249,142 +0.76%
packages/@rescript/runtime/Primitive_list.resi 91,801 92,483 +0.74%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,348 113,182 +0.74%
packages/@rescript/runtime/Primitive_float_extern.res 93,518 94,209 +0.74%
packages/@rescript/runtime/Stdlib_Null.resi 204,429 205,931 +0.73%
packages/@rescript/runtime/Stdlib_Type.resi 135,842 136,839 +0.73%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,839 161,011 +0.73%
packages/@rescript/runtime/Stdlib_Iterator.resi 159,300 160,466 +0.73%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,003 123,892 +0.72%
packages/@rescript/belt/src/Belt_HashMap.resi 296,822 298,955 +0.72%
packages/@rescript/belt/src/Belt_Result.resi 240,078 241,790 +0.71%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res 308,018 310,204 +0.71%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,327 150,386 +0.71%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res 111,971 112,762 +0.71%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,038 106,787 +0.71%
packages/@rescript/runtime/Stdlib_Iterable.resi 98,083 98,773 +0.70%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi 98,232 98,922 +0.70%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res 159,811 160,933 +0.70%
packages/@rescript/runtime/Primitive_promise.res 96,893 97,573 +0.70%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,334 136,270 +0.69%
packages/@rescript/runtime/Stdlib_Ordering.res 152,756 153,793 +0.68%
packages/@rescript/runtime/Stdlib_File.res 95,545 96,190 +0.68%
build/no-op 9,323,101 9,260,836 -0.67%
packages/@rescript/runtime/Obj.res 98,995 99,655 +0.67%
packages/@rescript/runtime/Dom.res 1,071,613 1,078,726 +0.66%
packages/@rescript/runtime/Stdlib_Pair.res 165,890 166,989 +0.66%
packages/@rescript/runtime/Stdlib_Blob.res 93,736 94,356 +0.66%
packages/@rescript/belt/src/Belt_internalBuckets.resi 222,956 224,408 +0.65%
packages/@rescript/belt/src/Belt_MutableSetInt.res 1,683,085 1,672,131 -0.65%
packages/@rescript/belt/src/Belt_MutableSetString.res 1,684,331 1,673,373 -0.65%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi 194,164 195,426 +0.65%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,839 166,909 +0.65%
packages/@rescript/belt/src/Belt_internalBucketsType.resi 164,638 165,683 +0.63%
packages/@rescript/runtime/Stdlib_Intl_Common.res 154,191 155,169 +0.63%
packages/@rescript/runtime/Stdlib_Iterable.res 98,775 99,394 +0.63%
packages/@rescript/runtime/Stdlib_AsyncIterable.res 98,846 99,465 +0.63%
packages/@rescript/runtime/Dom_storage.res 167,369 168,410 +0.62%
packages/@rescript/runtime/Stdlib_Generator.resi 160,461 161,459 +0.62%
packages/@rescript/runtime/RescriptTools.res 104,416 105,061 +0.62%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res 107,368 107,987 +0.58%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res 268,658 270,197 +0.57%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res 115,240 115,895 +0.57%
packages/@rescript/runtime/Stdlib_Iterator.res 235,490 236,809 +0.56%
packages/@rescript/runtime/Stdlib_Intl.res 174,054 175,011 +0.55%
packages/@rescript/runtime/Primitive_object.res 1,170,234 1,163,880 -0.54%
packages/@rescript/runtime/Primitive_bool.res 147,530 148,306 +0.53%
packages/@rescript/runtime/Primitive_float.res 147,571 148,345 +0.52%
packages/@rescript/runtime/Primitive_string.res 160,327 161,154 +0.52%
packages/@rescript/runtime/Primitive_array.res 193,362 194,358 +0.52%
packages/@rescript/runtime/Primitive_int.res 172,694 173,572 +0.51%
packages/@rescript/runtime/Stdlib_IterableIterator.res 178,969 179,857 +0.50%
packages/@rescript/runtime/Primitive_bigint.res 178,166 179,044 +0.49%
packages/@rescript/runtime/Stdlib_Lazy.res 222,117 223,206 +0.49%
packages/@rescript/runtime/Stdlib_AsyncIterator.res 295,604 297,046 +0.49%
packages/@rescript/runtime/Primitive_list.res 205,277 206,227 +0.46%
packages/@rescript/runtime/Stdlib_Global.res 141,632 142,257 +0.44%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res 211,563 212,489 +0.44%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res 228,831 229,828 +0.44%
packages/@rescript/belt/src/Belt_Option.res 391,883 393,575 +0.43%
packages/@rescript/runtime/Stdlib_Generator.res 200,653 201,519 +0.43%
packages/@rescript/runtime/Stdlib_Symbol.res 146,342 146,961 +0.42%
stress/LetRec.res 32,165,761 32,299,528 +0.42%
packages/@rescript/belt/src/Belt_Map.res 989,277 993,368 +0.41%
packages/@rescript/runtime/Stdlib_JsError.res 230,502 231,423 +0.40%
packages/@rescript/runtime/Primitive_exceptions.res 202,176 202,975 +0.40%
packages/@rescript/runtime/Stdlib_Null.res 334,093 335,406 +0.39%
packages/@rescript/runtime/Stdlib_Nullable.res 331,677 332,975 +0.39%
packages/@rescript/runtime/Primitive_js_extern.res 239,948 240,887 +0.39%
packages/@rescript/belt/src/Belt_Float.res 165,068 165,708 +0.39%
packages/@rescript/belt/src/Belt_Set.res 865,401 868,753 +0.39%
packages/@rescript/belt/src/Belt_Int.res 165,806 166,446 +0.39%
packages/@rescript/belt/src/Belt_Result.res 412,200 413,786 +0.38%
packages/@rescript/runtime/Stdlib_RegExp.res 163,572 164,196 +0.38%
packages/@rescript/belt/src/Belt.res 188,357 189,075 +0.38%
packages/@rescript/runtime/Stdlib_Dict.res 320,385 321,603 +0.38%
packages/@rescript/belt/src/Belt_SortArrayInt.res 1,360,036 1,354,989 -0.37%
packages/@rescript/belt/src/Belt_SortArrayString.res 1,361,826 1,356,790 -0.37%
packages/@rescript/runtime/Stdlib_Bool.res 146,294 146,827 +0.36%
packages/@rescript/belt/src/Belt_MapDict.res 1,645,238 1,650,770 +0.34%
packages/@rescript/belt/src/Belt_Id.res 290,420 291,377 +0.33%
packages/@rescript/runtime/Stdlib_Type.res 201,825 202,487 +0.33%
packages/@rescript/runtime/Stdlib_Map.res 205,588 206,253 +0.32%
packages/@rescript/runtime/Stdlib_Set.res 210,937 211,603 +0.32%
packages/@rescript/belt/src/Belt_MutableQueue.res 799,497 801,918 +0.30%
packages/@rescript/belt/src/Belt_SetDict.res 1,459,153 1,463,560 +0.30%
packages/@rescript/runtime/Stdlib_IteratorObject.res 250,798 251,550 +0.30%
packages/@rescript/belt/src/Belt_internalBucketsType.res 292,621 293,488 +0.30%
packages/@rescript/runtime/Stdlib_Temporal_Now.res 143,368 143,782 +0.29%
packages/@rescript/runtime/Stdlib_Option.res 762,258 764,453 +0.29%
build/shared-edit 72,992,698 72,785,048 -0.28%
packages/@rescript/runtime/Stdlib_Float.res 219,276 219,870 +0.27%
packages/@rescript/runtime/Stdlib_DataView.res 230,137 230,757 +0.27%
packages/@rescript/belt/src/Belt_MutableStack.res 390,405 391,447 +0.27%
packages/@rescript/belt/src/Belt_MutableMap.res 1,314,131 1,317,629 +0.27%
packages/@rescript/belt/src/Belt_internalSetBuckets.res 704,425 706,254 +0.26%
packages/@rescript/belt/src/Belt_internalBuckets.res 975,308 977,787 +0.25%
build/WideDeps/clean 371,586,826 372,525,944 +0.25%
packages/@rescript/runtime/Stdlib_Temporal_Common.res 366,499 367,415 +0.25%
packages/@rescript/runtime/Stdlib_BigInt.res 207,266 207,777 +0.25%
packages/@rescript/belt/src/Belt_MutableSet.res 1,923,153 1,927,882 +0.25%
packages/@rescript/belt/src/Belt_internalMapInt.res 1,423,350 1,426,834 +0.24%
packages/@rescript/belt/src/Belt_internalMapString.res 1,425,194 1,428,680 +0.24%
packages/@rescript/runtime/Stdlib_Array.res 1,291,788 1,294,865 +0.24%
packages/@rescript/runtime/Stdlib.res 982,667 984,897 +0.23%
packages/@rescript/runtime/RescriptTools_Docgen.res 283,715 284,356 +0.23%
packages/@rescript/belt/src/Belt_HashSet.res 986,522 988,718 +0.22%
packages/@rescript/belt/src/Belt_HashSetString.res 858,327 856,418 -0.22%
packages/@rescript/belt/src/Belt_HashSetInt.res 858,010 856,104 -0.22%
packages/@rescript/belt/src/Belt_MapInt.res 1,190,580 1,193,155 +0.22%
packages/@rescript/belt/src/Belt_MapString.res 1,191,116 1,193,691 +0.22%
packages/@rescript/belt/src/Belt_internalAVLtree.res 3,550,508 3,558,096 +0.21%
packages/@rescript/runtime/Stdlib_Result.res 1,279,779 1,282,504 +0.21%
packages/@rescript/runtime/Stdlib_List.res 2,724,289 2,729,875 +0.21%
packages/@rescript/runtime/Primitive_hash.res 974,400 972,444 -0.20%
packages/@rescript/runtime/Stdlib_Promise.res 352,826 353,524 +0.20%
packages/@rescript/belt/src/Belt_List.res 3,218,112 3,224,426 +0.20%
packages/@rescript/belt/src/Belt_Array.res 2,182,604 2,186,770 +0.19%
build/WideDeps/edit 166,060,557 166,370,072 +0.19%
packages/@rescript/runtime/Stdlib_Console.res 370,395 371,047 +0.18%
build/clean 237,620,319 238,008,609 +0.16%
packages/@rescript/runtime/Stdlib_Math.res 328,145 328,663 +0.16%
packages/@rescript/belt/src/Belt_HashMap.res 1,210,726 1,212,588 +0.15%
packages/@rescript/runtime/Stdlib_JSON.res 297,904 298,358 +0.15%
packages/@rescript/runtime/Stdlib_Int.res 458,001 458,681 +0.15%
packages/@rescript/belt/src/Belt_internalAVLset.res 2,912,349 2,915,771 +0.12%
packages/@rescript/belt/src/Belt_HashMapInt.res 1,070,365 1,071,581 +0.11%
packages/@rescript/belt/src/Belt_HashMapString.res 1,071,077 1,072,290 +0.11%
packages/@rescript/belt/src/Belt_internalSetInt.res 737,597 736,848 -0.10%
packages/@rescript/belt/src/Belt_internalSetString.res 738,788 738,040 -0.10%

Instructions

In total: 9,215,352,773 → 8,599,575,283 (-6.68%).

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

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

Benchmark Base Head Change
stress/ObjectFields.res 944,894,619 188,740,804 -80.03%
stress/Record.res 1,071,651,340 1,186,222,118 +10.69%
packages/@rescript/runtime/JsxDOM.res 117,356,011 120,252,358 +2.47%
packages/@rescript/runtime/JsxDOMStyle.res 95,313,695 97,055,881 +1.83%
packages/@rescript/runtime/Stdlib_String.resi 29,701,699 30,226,210 +1.77%
packages/@rescript/runtime/Stdlib_Date.resi 34,530,288 35,107,606 +1.67%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,572,433 42,261,809 +1.66%
stress/InlineChain.res 137,221,202 134,997,924 -1.62%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,449,507 31,905,360 +1.45%
stress/LetRec.res 1,371,842,885 1,391,494,378 +1.43%
9 more changes
Benchmark Base Head Change
packages/@rescript/belt/src/Belt_Array.resi 33,957,087 34,405,533 +1.32%
packages/@rescript/belt/src/Belt_List.resi 39,221,209 39,718,780 +1.27%
packages/@rescript/runtime/Stdlib_Array.resi 40,352,925 40,808,771 +1.13%
packages/@rescript/runtime/Stdlib_Math.resi 21,547,212 21,776,058 +1.06%
packages/@rescript/runtime/Stdlib_List.resi 24,771,082 24,984,021 +0.86%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,767,351 25,981,887 +0.83%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,320,904 24,503,830 +0.75%
stress/TypeAliasChain.res 171,978,427 171,149,219 -0.48%
packages/@rescript/belt/src/Belt_List.res 117,825,723 118,004,418 +0.15%

Output size

In total: 25,920,835 → 25,703,492 (-0.84%).

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

Benchmark Base Head Change
output/tests/*.cmt 11,081,712 10,922,067 -1.44%
output/belt/*.cmt 2,752,575 2,713,655 -1.41%
output/tests/*.cmi 2,352,388 2,339,354 -0.55%
output/runtime/*.cmt 3,035,969 3,029,818 -0.20%

Pull request 8541c8e compared with base a826170 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: 8541c8e

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 33709fb to 8541c8e Compare November 20, 2026 21:10

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