Repository navigation
Instantiate non-generic types without a copy session - #9411
Conversation
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Changelog🏠 Internal
Semantic Diff1 commit · Full page Instantiate non-generic types without a copy session2e243f5 · 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. |
There was a problem hiding this comment.
💡 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".
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🎉 Compiler benchmarksAllocated wordsIn 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.
218 more changes
InstructionsIn total: 9,225,173,628 → 9,128,430,307 (-1.05%). 🎉 Improvement: 8 benchmarks execute more than 1% fewer instructions.
5 more changes
Output sizeIn 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. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9411 |
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
27a7389 to
252535e
Compare
|
@codex review |
252535e to
580e1e7
Compare
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
cristianoc
left a comment
There was a problem hiding this comment.
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>
580e1e7 to
2e243f5
Compare
|
@cristianoc Thanks. Here is why the shortcut can't change anything, followed by a check over the whole test suite. Argument. With let ty = repr ty in
match ty.desc with
| Tsubst ty -> ty
| _ -> if ty.level <> generic_level && partial = None then ty else ...
The Check. I temporarily changed Reply drafted by Claude. |
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.instanceandinstance_defopened a copy session even for a type that is neither generic nor marked by an enclosing session.copyreturns such a type as it is, without writing anything.Typecoreinstantiates the expected type of every expression this way, so each of these sessions allocated a session record for nothing. Now:warning_scopeskips its attribute walk when there are no attributes.Measured:
tests/testsfiles, compiling allocates 3.7% fewer words, 3.9% fewer in the minor heap. JS and diagnostics are byte-identical.tests/tests(690 modules) writes the same 3,484 files,.cmi,.cmj,.cmtand.astincluded.New tests:
tests/ounit_tests/ounit_instance_tests.mlchecks:partialinstances 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