Skip to content

Instantiate non-generic types without a copy session - #9411

Merged
cknitt merged 1 commit into
masterfrom
skip-noop-copy-sessions
Nov 30, 2026
Merged

cknitt merged 1 commit into
masterfrom
skip-noop-copy-sessions

Conversation

@cknitt

@cknitt cknitt commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Every minor collection stops all compiler workers, so allocation in the type checker slows parallel builds down. An allocation profile showed small allocations from copy sessions that do nothing.

Ctype.instance and instance_def opened a copy session even for a type that is neither generic nor marked by an enclosing session. copy returns such a type as it is, without writing anything. Typecore instantiates the expected type of every expression this way, so each of these sessions allocated a session record for nothing. Now:

  • such types are returned directly;
  • marked types and partial instances still go through a session;
  • warning_scope skips its attribute walk when there are no attributes.

Measured:

  • On 77 Belt and tests/tests files, compiling allocates 3.7% fewer words, 3.9% fewer in the minor heap. JS and diagnostics are byte-identical.
  • A clean build of tests/tests (690 modules) writes the same 3,484 files, .cmi, .cmj, .cmt and .ast included.
  • Build time is within noise on linux-arm64.

New tests: tests/ounit_tests/ounit_instance_tests.ml checks:

  • a non-generic type and its structure come back physically the same;
  • a link is followed;
  • a generic variable is still copied;
  • a node marked by an enclosing session gives that session's copy;
  • partial instances still replace a non-generic variable by a fresh one.

Letting marked nodes or partial instances take the shortcut makes these tests fail.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH

@cknitt

cknitt commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-25T20:25:36.835868Z 580e1e7 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.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Instantiate types that aren't generic without opening a copy session, so type checking allocates a little less.

Semantic Diff

1 commit · Full page

Instantiate non-generic types without a copy session

2e243f5 · cknitt + Claude · Nov 25, 2026, 20:23 UTC

Ctype.instance and instance_def opened a copy session even for a type that is neither generic nor marked by an enclosing session, which copy returns as it is. Typecore instantiates the expected type of every expression this way, so each of these empty sessions allocated for nothing. They now return the representative directly; marked types and partial instances still take the session. warning_scope skips empty attribute lists, which also saves the closure of its partial application.

Allocation matters because every minor collection stops all compiler workers. On 77 Belt and tests/tests files, compiling allocates 3.7% fewer words, with byte-identical JS and diagnostics; a clean build of tests/tests (690 modules) writes the same 3484 files, .cmi, .cmj, .cmt and .ast included. Build time is within noise.

Unit tests in tests/ounit_tests/ounit_instance_tests.ml check that a non-generic type and its structure come back as they are, that links are followed, that generic variables and links to generic or marked nodes are still copied, that a node marked by an enclosing session gives that session's copy, and that partial instances still replace a non-generic variable by a fresh one.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1cee7c2dd7

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

Comment thread compiler/typing/ctype.ml Resolved
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.49%. Comparing base (5e5a3a7) to head (2e243f5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9411      +/-   ##
==========================================
+ Coverage   82.47%   82.49%   +0.02%     
==========================================
  Files         466      467       +1     
  Lines       66070    66125      +55     
==========================================
+ Hits        54493    54553      +60     
+ Misses      11577    11572       -5     
Files with missing lines Coverage Δ
compiler/typing/builtin_attributes.ml 83.67% <100.00%> (ø)
compiler/typing/ctype.ml 70.73% <100.00%> (+0.30%) ⬆️
tests/ounit_tests/ounit_instance_tests.ml 100.00% <100.00%> (ø)
tests/ounit_tests/ounit_tests_main.ml 100.00% <ø> (ø)
🚀 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.

@cknitt

cknitt commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e5e1dba09a

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

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🎉 Compiler benchmarks

Allocated words

In total: 674,904,508 → 655,171,920 (-2.92%).

Generated projects: 630,567,307 → 627,297,775 (-0.52%).

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

Benchmark Base Head Change
stress/NestedClosures.res 10,276,559 9,295,346 -9.55%
stress/Record.res 26,150,062 24,087,754 -7.89%
stress/LetRec.res 31,641,992 29,217,899 -7.66%
stress/ListLiteral.res 3,400,826 3,202,745 -5.82%
packages/@rescript/belt/src/Belt_Array.res 2,155,725 2,042,965 -5.23%
packages/@rescript/belt/src/Belt_SortArray.res 1,448,739 1,374,004 -5.16%
packages/@rescript/belt/src/Belt_SortArrayInt.res 1,343,380 1,276,495 -4.98%
packages/@rescript/belt/src/Belt_SortArrayString.res 1,345,170 1,278,318 -4.97%
packages/@rescript/runtime/Primitive_object.res 1,157,633 1,107,750 -4.31%
stress/InlineChain.res 3,559,996 3,409,348 -4.23%
218 more changes
Benchmark Base Head Change
build/shared-edit 87,817,850 84,102,611 -4.23%
packages/@rescript/belt/src/Belt_internalAVLset.res 2,882,050 2,762,124 -4.16%
packages/@rescript/runtime/Stdlib_List.res 2,693,088 2,582,207 -4.12%
packages/@rescript/belt/src/Belt_internalAVLtree.res 3,510,171 3,365,852 -4.11%
packages/@rescript/runtime/Primitive_hash.res 963,863 925,333 -4.00%
packages/@rescript/belt/src/Belt_List.res 3,182,676 3,061,289 -3.81%
build/no-op 9,349,530 8,994,755 -3.79%
build/leaf-edit 12,082,396 11,626,183 -3.78%
packages/@rescript/belt/src/Belt_MutableSet.res 1,900,871 1,831,070 -3.67%
packages/@rescript/runtime/Stdlib_Array.res 1,284,814 1,238,375 -3.61%
packages/@rescript/belt/src/Belt_MutableSetInt.res 1,662,857 1,603,722 -3.56%
packages/@rescript/belt/src/Belt_MutableSetString.res 1,664,103 1,604,962 -3.55%
packages/@rescript/belt/src/Belt_internalBuckets.res 970,123 935,830 -3.53%
packages/@rescript/belt/src/Belt_MutableQueue.res 792,242 764,303 -3.53%
packages/@rescript/belt/src/Belt_HashMap.res 1,201,622 1,161,938 -3.30%
packages/@rescript/belt/src/Belt_HashSet.res 979,582 947,314 -3.29%
packages/@rescript/belt/src/Belt_HashSetInt.res 851,911 824,183 -3.25%
packages/@rescript/belt/src/Belt_HashSetString.res 852,233 824,498 -3.25%
packages/@rescript/runtime/Primitive_option.res 298,158 288,547 -3.22%
packages/@rescript/belt/src/Belt_HashMapInt.res 1,062,335 1,028,373 -3.20%
packages/@rescript/belt/src/Belt_HashMapString.res 1,063,043 1,029,083 -3.19%
packages/@rescript/belt/src/Belt_Range.res 289,195 279,967 -3.19%
packages/@rescript/runtime/Primitive_module.res 337,202 326,678 -3.12%
packages/@rescript/runtime/Primitive_array.res 192,256 186,298 -3.10%
packages/@rescript/belt/src/Belt_internalSetBuckets.res 702,145 680,502 -3.08%
packages/@rescript/belt/src/Belt_MutableMap.res 1,302,107 1,264,041 -2.92%
packages/@rescript/belt/src/Belt_internalMapInt.res 1,409,657 1,368,882 -2.89%
packages/@rescript/belt/src/Belt_internalMapString.res 1,411,501 1,370,726 -2.89%
packages/@rescript/belt/src/Belt_Set.res 857,736 833,154 -2.87%
packages/@rescript/belt/src/Belt_Map.res 981,032 953,270 -2.83%
packages/@rescript/belt/src/Belt_internalSetInt.res 731,748 711,919 -2.71%
packages/@rescript/belt/src/Belt_internalSetString.res 732,939 713,110 -2.71%
packages/@rescript/belt/src/Belt_MutableMapInt.res 1,154,189 1,122,995 -2.70%
packages/@rescript/belt/src/Belt_MutableMapString.res 1,154,468 1,123,274 -2.70%
packages/@rescript/runtime/Primitive_list.res 204,184 198,902 -2.59%
packages/@rescript/runtime/Stdlib_Lazy.res 221,656 215,947 -2.58%
packages/@rescript/belt/src/Belt_MapDict.res 1,635,172 1,593,521 -2.55%
packages/@rescript/belt/src/Belt_Option.res 389,772 380,145 -2.47%
packages/@rescript/belt/src/Belt_MutableStack.res 388,072 378,511 -2.46%
build/clean 260,349,666 253,955,062 -2.46%
packages/@rescript/runtime/Stdlib_Nullable.res 332,940 324,939 -2.40%
packages/@rescript/belt/src/Belt_SetDict.res 1,449,423 1,415,561 -2.34%
packages/@rescript/runtime/Stdlib_Null.res 335,436 327,774 -2.28%
packages/@rescript/runtime/Stdlib_Int.res 455,641 445,261 -2.28%
packages/@rescript/belt/src/Belt_SetInt.res 1,293,080 1,263,656 -2.28%
packages/@rescript/belt/src/Belt_SetString.res 1,293,809 1,264,387 -2.27%
packages/@rescript/runtime/Stdlib_Option.res 757,501 740,810 -2.20%
stress/RefsInLoop.res 16,471,657 16,120,558 -2.13%
packages/@rescript/belt/src/Belt_MapInt.res 1,185,508 1,160,263 -2.13%
packages/@rescript/belt/src/Belt_MapString.res 1,186,044 1,160,806 -2.13%
packages/@rescript/runtime/Primitive_string.res 159,885 156,594 -2.06%
packages/@rescript/runtime/Primitive_int.res 172,188 168,672 -2.04%
packages/@rescript/runtime/Stdlib_Result.res 1,273,829 1,248,172 -2.01%
packages/@rescript/runtime/Primitive_bigint.res 177,662 174,086 -2.01%
packages/@rescript/runtime/Stdlib_JsError.res 230,921 226,382 -1.97%
packages/@rescript/runtime/Stdlib_AsyncIterator.res 295,123 289,492 -1.91%
packages/@rescript/runtime/Primitive_exceptions.res 201,574 197,761 -1.89%
packages/@rescript/belt/src/Belt_Result.res 410,356 402,881 -1.82%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res 211,800 208,233 -1.68%
packages/@rescript/belt/src/Belt_internalBucketsType.res 291,993 287,147 -1.66%
packages/@rescript/runtime/Primitive_float.res 147,214 144,793 -1.64%
packages/@rescript/belt/src/Belt_MapDict.resi 511,546 503,326 -1.61%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res 229,132 225,574 -1.55%
packages/@rescript/runtime/Stdlib_Ordering.res 155,305 152,935 -1.53%
packages/@rescript/runtime/Stdlib_Type.res 201,856 198,877 -1.48%
packages/@rescript/runtime/Stdlib_Pair.res 166,565 164,192 -1.42%
packages/@rescript/runtime/Stdlib_Generator.res 201,514 198,661 -1.42%
packages/@rescript/runtime/Stdlib_JsExn.res 173,621 171,236 -1.37%
packages/@rescript/runtime/Stdlib_Iterator.res 235,310 232,139 -1.35%
packages/@rescript/belt/src/Belt_internalAVLtree.resi 452,399 446,516 -1.30%
packages/@rescript/belt/src/Belt_Map.resi 576,057 568,597 -1.30%
packages/@rescript/runtime/Stdlib_String.res 506,012 499,496 -1.29%
packages/@rescript/runtime/Stdlib_JSON.res 297,732 293,997 -1.25%
packages/@rescript/runtime/Dom_storage.res 168,380 166,280 -1.25%
packages/@rescript/belt/src/Belt_MutableMap.resi 394,186 389,518 -1.18%
packages/@rescript/runtime/Stdlib_Bool.res 146,673 144,939 -1.18%
packages/@rescript/belt/src/Belt_List.resi 750,422 741,563 -1.18%
packages/@rescript/runtime/Stdlib_Result.resi 295,049 291,632 -1.16%
packages/@rescript/belt/src/Belt_SetDict.resi 400,250 395,822 -1.11%
packages/@rescript/runtime/Stdlib_Promise.res 353,453 349,628 -1.08%
packages/@rescript/belt/src/Belt_MapString.resi 389,490 385,296 -1.08%
packages/@rescript/belt/src/Belt_MapInt.resi 389,533 385,339 -1.08%
packages/@rescript/runtime/Stdlib_List.resi 406,435 402,079 -1.07%
packages/@rescript/belt/src/Belt_Array.resi 645,109 638,368 -1.04%
packages/@rescript/runtime/Stdlib_Math.res 328,102 324,730 -1.03%
packages/@rescript/runtime/Stdlib_Dict.res 321,235 317,962 -1.02%
packages/@rescript/runtime/Stdlib_IterableIterator.res 179,669 177,839 -1.02%
packages/@rescript/runtime/Pervasives.res 240,136 237,697 -1.02%
packages/@rescript/runtime/Stdlib_IteratorObject.res 251,466 248,925 -1.01%
packages/@rescript/runtime/Stdlib_Float.res 219,312 217,161 -0.98%
packages/@rescript/runtime/Stdlib_BigInt.res 207,630 205,662 -0.95%
packages/@rescript/belt/src/Belt_internalAVLset.resi 354,811 351,481 -0.94%
packages/@rescript/belt/src/Belt_MutableSet.resi 395,038 391,378 -0.93%
packages/@rescript/belt/src/Belt_MutableMapString.resi 313,673 310,793 -0.92%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 313,791 310,911 -0.92%
packages/@rescript/belt/src/Belt_Set.resi 434,798 430,814 -0.92%
packages/@rescript/runtime/Stdlib_Array.resi 725,582 719,267 -0.87%
packages/@rescript/belt/src/Belt_SortArray.resi 253,180 251,026 -0.85%
packages/@rescript/runtime/Stdlib_Option.resi 235,309 233,326 -0.84%
packages/@rescript/runtime/Stdlib_Promise.resi 355,694 352,793 -0.82%
packages/@rescript/runtime/Primitive_bool.res 147,472 146,272 -0.81%
packages/@rescript/runtime/Stdlib_Map.res 206,214 204,579 -0.79%
packages/@rescript/runtime/Stdlib_Set.res 211,558 209,914 -0.78%
packages/@rescript/runtime/Stdlib_Date.res 552,905 548,789 -0.74%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res 159,721 158,551 -0.73%
packages/@rescript/belt/src/Belt_Id.res 290,570 288,470 -0.72%
packages/@rescript/runtime/Stdlib_TypedArray.res 786,012 780,456 -0.71%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 233,994 232,353 -0.70%
packages/@rescript/belt/src/Belt_HashMap.resi 295,462 293,395 -0.70%
packages/@rescript/belt/src/Belt_Option.resi 241,658 240,005 -0.68%
packages/@rescript/belt/src/Belt_HashMapString.resi 213,588 212,181 -0.66%
packages/@rescript/belt/src/Belt_HashMapInt.resi 213,702 212,295 -0.66%
packages/@rescript/belt/src/Belt_Result.resi 239,344 237,790 -0.65%
packages/@rescript/runtime/JsxDOM.res 2,664,034 2,646,832 -0.65%
build/WideDeps/clean 371,743,341 369,398,360 -0.63%
packages/@rescript/runtime/Stdlib_Intl_Common.res 154,641 153,711 -0.60%
packages/@rescript/belt/src/Belt_MutableQueue.resi 206,148 204,909 -0.60%
stress/ObjectFields.res 20,675,770 20,552,089 -0.60%
packages/@rescript/belt/src/Belt_HashSet.resi 222,672 221,364 -0.59%
packages/@rescript/belt/src/Belt_Float.res 165,331 164,368 -0.58%
packages/@rescript/belt/src/Belt_Int.res 166,070 165,107 -0.58%
packages/@rescript/runtime/RescriptTools_Docgen.resi 273,746 272,216 -0.56%
packages/@rescript/belt/src/Belt_internalBuckets.resi 223,228 221,986 -0.56%
packages/@rescript/runtime/Stdlib_Iterator.resi 158,762 157,892 -0.55%
packages/@rescript/belt/src/Belt_MutableSetString.resi 264,006 262,560 -0.55%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 264,123 262,677 -0.55%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res 405,144 402,942 -0.54%
packages/@rescript/runtime/Stdlib_Dict.resi 240,212 238,919 -0.54%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res 373,749 371,742 -0.54%
packages/@rescript/runtime/RescriptTools_Docgen.res 283,979 282,455 -0.54%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 177,264 176,313 -0.54%
packages/@rescript/belt/src/Belt_Id.resi 260,316 258,963 -0.52%
packages/@rescript/runtime/Stdlib_Map.resi 216,838 215,713 -0.52%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res 382,429 380,464 -0.51%
packages/@rescript/belt/src/Belt_SetString.resi 258,680 257,354 -0.51%
packages/@rescript/belt/src/Belt_SetInt.resi 258,807 257,481 -0.51%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res 268,380 267,009 -0.51%
packages/@rescript/runtime/Stdlib_Nullable.resi 198,836 197,831 -0.51%
packages/@rescript/runtime/Stdlib_Null.resi 203,543 202,541 -0.49%
packages/@rescript/runtime/Stdlib_Set.resi 228,617 227,495 -0.49%
packages/@rescript/runtime/JsxDOMStyle.res 1,935,780 1,926,300 -0.49%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res 320,397 318,834 -0.49%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res 307,735 306,238 -0.49%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 438,355 436,276 -0.47%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 404,061 402,162 -0.47%
stress/IntSwitch.res 29,766,446 29,626,553 -0.47%
packages/@rescript/runtime/Stdlib_Generator.resi 160,253 159,500 -0.47%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res 389,888 388,058 -0.47%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,631 164,854 -0.47%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 574,307 571,658 -0.46%
packages/@rescript/runtime/Stdlib_Console.res 370,515 368,811 -0.46%
build/Namespace/edit 7,942,721 7,906,406 -0.46%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,163 148,500 -0.44%
packages/@rescript/runtime/Stdlib_Temporal_Common.res 366,949 365,353 -0.43%
packages/@rescript/runtime/Stdlib_Date.resi 612,730 610,096 -0.43%
packages/@rescript/runtime/Stdlib_Console.resi 410,791 409,087 -0.41%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,631 158,971 -0.41%
packages/@rescript/runtime/JsxEvent.res 1,092,809 1,088,336 -0.41%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,579 174,889 -0.39%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,692 175,002 -0.39%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,059 168,402 -0.39%
packages/@rescript/runtime/Primitive_js_extern.res 240,162 239,253 -0.38%
build/WideDeps/edit 166,080,641 165,456,109 -0.38%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi 194,448 193,728 -0.37%
packages/@rescript/runtime/Stdlib_String.resi 495,962 494,150 -0.37%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res 202,178 201,458 -0.36%
packages/@rescript/runtime/Stdlib_DataView.res 230,614 229,804 -0.35%
packages/@rescript/runtime/Stdlib_Math.resi 327,333 326,301 -0.32%
packages/@rescript/runtime/Stdlib_Intl_Collator.res 178,949 178,391 -0.31%
build/Namespace/clean 84,800,604 84,536,900 -0.31%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res 180,751 180,193 -0.31%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,790 135,376 -0.30%
packages/@rescript/runtime/Stdlib_DataView.resi 267,696 266,886 -0.30%
packages/@rescript/runtime/Stdlib_JSON.resi 235,736 235,028 -0.30%
packages/@rescript/runtime/Stdlib_Intl_Locale.res 198,363 197,769 -0.30%
packages/@rescript/runtime/Stdlib_Object.res 247,689 246,960 -0.29%
packages/@rescript/runtime/Dom.res 1,072,063 1,068,935 -0.29%
packages/@rescript/runtime/Stdlib_Int.resi 205,591 204,997 -0.29%
packages/@rescript/runtime/Stdlib_JsError.resi 184,185 183,663 -0.28%
packages/@rescript/runtime/Stdlib_BigInt.resi 185,473 184,957 -0.28%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res 170,112 169,650 -0.27%
packages/@rescript/belt/src/Belt_internalBucketsType.resi 164,926 164,482 -0.27%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res 115,760 115,451 -0.27%
packages/@rescript/runtime/Primitive_array_extern.res 114,506 114,203 -0.26%
packages/@rescript/runtime/Stdlib_RegExp.res 164,051 163,619 -0.26%
packages/@rescript/runtime/Stdlib_Global.res 142,114 141,748 -0.26%
packages/@rescript/belt/src/Belt_Range.resi 176,183 175,733 -0.26%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,375 168,979 -0.23%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,493 169,097 -0.23%
packages/@rescript/runtime/Stdlib_Float.resi 193,609 193,177 -0.22%
stress/PolyVariantSwitch.res 14,274,592 14,243,089 -0.22%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,643 187,235 -0.22%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res 154,826 154,496 -0.21%
packages/@rescript/runtime/Stdlib_Global.resi 155,424 155,094 -0.21%
packages/@rescript/runtime/Primitive_object.resi 117,311 117,071 -0.20%
packages/@rescript/runtime/Jsx.res 122,026 121,777 -0.20%
packages/@rescript/runtime/Primitive_option.resi 122,401 122,155 -0.20%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,458 123,218 -0.19%
packages/@rescript/runtime/Stdlib.res 982,806 981,060 -0.18%
packages/@rescript/runtime/Primitive_object_extern.res 115,017 114,819 -0.17%
packages/@rescript/runtime/Stdlib_Type.resi 135,942 135,714 -0.17%
packages/@rescript/runtime/Primitive_dict.res 102,998 102,833 -0.16%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,487 122,295 -0.16%
packages/@rescript/runtime/Stdlib_Intl.res 174,496 174,232 -0.15%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,370 112,202 -0.15%
packages/@rescript/runtime/Stdlib_Symbol.res 146,811 146,595 -0.15%
packages/@rescript/runtime/Dom_storage2.res 120,471 120,297 -0.14%
packages/@rescript/runtime/Primitive_module.resi 103,396 103,249 -0.14%
packages/@rescript/runtime/Stdlib_Symbol.resi 159,945 159,735 -0.13%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,280 106,142 -0.13%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 116,885 116,735 -0.13%
packages/@rescript/runtime/Primitive_hash.resi 102,954 102,822 -0.13%
packages/@rescript/belt/src/Belt_Int.resi 149,428 149,248 -0.12%
packages/@rescript/belt/src/Belt_Float.resi 150,908 150,728 -0.12%
packages/@rescript/runtime/Stdlib_Bool.resi 116,590 116,452 -0.12%
packages/@rescript/belt/src/Belt.res 188,801 188,591 -0.11%
packages/@rescript/runtime/Primitive_promise.res 97,345 97,237 -0.11%
packages/@rescript/runtime/Primitive_exceptions.resi 100,537 100,429 -0.11%

Instructions

In total: 9,225,173,628 → 9,128,430,307 (-1.05%).

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

Benchmark Base Head Change
stress/Record.res 1,072,487,483 1,036,304,792 -3.37%
stress/NestedClosures.res 529,991,434 517,307,200 -2.39%
stress/LetRec.res 1,379,239,315 1,348,692,438 -2.21%
stress/ListLiteral.res 131,188,931 129,285,931 -1.45%
stress/InlineChain.res 139,178,937 137,338,958 -1.32%
packages/@rescript/belt/src/Belt_internalAVLtree.res 136,452,281 134,651,783 -1.32%
packages/@rescript/belt/src/Belt_List.res 118,212,326 116,706,409 -1.27%
stress/RefsInLoop.res 392,502,481 388,449,696 -1.03%
stress/ObjectFields.res 946,073,630 942,374,498 -0.39%
packages/@rescript/belt/src/Belt_List.resi 38,858,410 38,769,728 -0.23%
5 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_List.resi 24,486,840 24,444,429 -0.17%
packages/@rescript/belt/src/Belt_Array.resi 33,643,662 33,598,584 -0.13%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,345,818 41,295,235 -0.12%
packages/@rescript/runtime/JsxDOM.res 117,222,472 117,080,095 -0.12%
packages/@rescript/runtime/Stdlib_Array.resi 39,996,764 39,951,531 -0.11%

Output size

In total: 27,368,415 → 27,368,788 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request 2e243f5 compared with base 5e5a3a7 in this run.

@cknitt
cknitt marked this pull request as ready for review November 25, 2026 18:16
@cknitt
cknitt requested a review from cristianoc November 25, 2026 18:16
@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 2e243f5

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 27a7389e32

ℹ️ 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 force-pushed the skip-noop-copy-sessions branch from 27a7389 to 252535e Compare November 25, 2026 20:22
@cknitt

cknitt commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cknitt
cknitt force-pushed the skip-noop-copy-sessions branch from 252535e to 580e1e7 Compare November 25, 2026 20:24
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 252535e7ee

ℹ️ 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 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 580e1e7466

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

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine in principle but make sure you either:

  • get a convincing argument that this optimisation is correct and does not change anything

or

  • get a dedicated explicit adversarial review, or ask for some fuzzing so we are more likely to find corner cases never exercised by the current tests

Ctype.instance and instance_def opened a copy session even for a type that
is neither generic nor marked by an enclosing session, which copy returns
as it is. Typecore instantiates the expected type of every expression this
way, so each of these empty sessions allocated for nothing. They now
return the representative directly; marked types and partial instances
still take the session. warning_scope skips empty attribute lists, which
also saves the closure of its partial application.

Allocation matters because every minor collection stops all compiler
workers. On 77 Belt and tests/tests files, compiling allocates 3.7% fewer
words, with byte-identical JS and diagnostics; a clean build of tests/tests
(690 modules) writes the same 3484 files, .cmi, .cmj, .cmt and .ast
included. Build time is within noise.

Unit tests in tests/ounit_tests/ounit_instance_tests.ml check that a
non-generic type and its structure come back as they are, that links are
followed, that generic variables and links to generic or marked nodes are
still copied, that a node marked by an enclosing session gives that
session's copy, and that partial instances still replace a non-generic
variable by a fresh one.

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 force-pushed the skip-noop-copy-sessions branch from 580e1e7 to 2e243f5 Compare November 30, 2026 09:44
@cknitt

cknitt commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@cristianoc Thanks. Here is why the shortcut can't change anything, followed by a check over the whole test suite.

Argument. With partial = None, copy ?env sch starts like this (ctype.ml):

let ty = repr ty in
match ty.desc with
| Tsubst ty -> ty
| _ -> if ty.level <> generic_level && partial = None then ty else ...

is_own_instance (repr sch) holds exactly when neither of those two cases applies, so copy would return repr sch itself.

  • On that path copy writes nothing. It doesn't call save_desc or dup_mutability, doesn't set Tsubst, and doesn't read env (gadt_env is only used further down). So the session that used to wrap it starts empty and ends empty. Pushing and popping it on the request-local stack is the only effect, and that's gone now.
  • repr can compress a link chain, which writes to the trail. Before, copy called it once. Now the shortcut calls it once, and in the fallback case copy calls it again on a node whose chain is already compressed, so nothing more gets written.
  • Callers get the same physical node as before, so any later unify or level change hits the same node.
  • Partial instances (partial = Some _) never take the shortcut, because copy can replace a non-generic variable there. Generic nodes and nodes marked Tsubst by an enclosing session don't take it either.

The warning_scope change only skips List.iter over List.rev [].

Check. I temporarily changed instance and instance_def so that every time they took the shortcut, they also ran the old with_copy_session (fun () -> copy ...) and called failwith if the result wasn't physically the same node. With that bsc, make lib, the ounit, mocha, project and docstring tests, make test-analysis and make test-gentype all pass, so nothing failed. The PR description already reports that a clean tests/tests build writes byte-identical .cmi/.cmj/.cmt/.js.

Reply drafted by Claude.

@cknitt
cknitt merged commit 4717690 into master Nov 30, 2026
23 checks passed
@cknitt
cknitt deleted the skip-noop-copy-sessions branch November 30, 2026 17:59
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.

3 participants