Skip to content

Conversation

majocha
Copy link
Contributor

@majocha majocha commented Sep 21, 2025

Description

Generating structural information for TType is slow. This adds some optimizations, most importantly memoization of generated type structures.
It is important to avoid holding strong references to TType in cache keys ( it was the point of #18875) so we use a weak table for memoization.

Fixes #18925

type check times are now roughly back to what they were before the regression (see #18925)

before #18875 (at commit 71167fb)
--------------------------------------------------------------------------------------------------------
|Phase name                          |Elapsed |Duration| WS(MB)|  GC0  |  GC1  |  GC2  |Handles|Threads|
|------------------------------------|--------|--------|-------|-------|-------|-------|-------|-------|
|Typecheck                           |  8.6085|  7.2778|   1574|     54|     23|      4|   1014|     83|

head (regression from 7 to 18 seconds)
--------------------------------------------------------------------------------------------------------
|Phase name                          |Elapsed |Duration| WS(MB)|  GC0  |  GC1  |  GC2  |Handles|Threads|
|------------------------------------|--------|--------|-------|-------|-------|-------|-------|-------|
|Typecheck                           | 20.3543| 18.5384|   1286|    939|    105|      3|    624|     71|


with this fix (back to circa 7 seconds)
--------------------------------------------------------------------------------------------------------
|Phase name                          |Elapsed |Duration| WS(MB)|  GC0  |  GC1  |  GC2  |Handles|Threads|
|------------------------------------|--------|--------|-------|-------|-------|-------|-------|-------|
|Typecheck                           |  8.6310|  7.3036|   1674|     54|     24|      3|    712|     71|

Caveat: this is amateur hour stuff, I have no CS background and no experience writing high performance code so any suggestions are super welcome.

Copy link
Contributor

github-actions bot commented Sep 21, 2025

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.100.md

@github-project-automation github-project-automation bot moved this from New to In Progress in F# Compiler and Tooling Sep 22, 2025
@T-Gro T-Gro merged commit ced09df into dotnet:main Sep 22, 2025
38 checks passed
@majocha majocha deleted the fix-typestructure-perf branch September 22, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

#18875 degraded typecheck performance
3 participants