Skip to content

Make ILTypeDef interface calculation lazy - #17392

Merged
psfinaki merged 9 commits into
dotnet:mainfrom
DedSec256:ber.a/lazyInterfaces
Sep 18, 2024
Merged

Make ILTypeDef interface calculation lazy#17392
psfinaki merged 9 commits into
dotnet:mainfrom
DedSec256:ber.a/lazyInterfaces

Conversation

@DedSec256

@DedSec256DedSec256 commented Jul 8, 2024

Copy link
Copy Markdown
Contributor

As stated in #16168
image

By analogy with custom attributes, reading interfaces is really time-consuming and ILTypeDef constructor is a public API but lacks the ability to pass lazy computation of interfaces.

This PR proposes the ability to pass lazy computation of interfaces to ILTypeDef constructor.

As evidence of the need for lazy calculation even for FCS default interfaces reading implementation, a benchmark was conducted for analysis of all files in ReSharper.FSharp/FSharp.Psi.Services with some additional unused opens,
48 files & 471 dll references required for project analysis were taken

MethodMeanErrorStdDevGen0Gen1Gen2Allocated
TypeCheckFiles - OLD5.758 s0.0510 s0.0477 s10000.00008000.00007000.00007.45 GB
TypeCheckFiles - NEW5.302 s0.0335 s0.0332 s4000.00002000.00001000.00007.02 GB

@github-actions

github-actionsBot commented Jul 8, 2024

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/9.0.100.md

@DedSec256DedSec256 changed the title Make ILTypeDef interface calculation lazy [WIP]Make ILTypeDef interface calculation lazyJul 18, 2024
@DedSec256
DedSec256 marked this pull request as ready for review July 18, 2024 17:30
@DedSec256
DedSec256 requested a review from a team as a code ownerJuly 18, 2024 17:30
@DedSec256

Copy link
Copy Markdown
ContributorAuthor

It appears that important conflicting changes have occurred during this time

@psfinaki

Copy link
Copy Markdown
Contributor

@DedSec256 yes, likely due to nullness finally merged, sorry. Let us know if you need any help with conflicts.

@T-GroT-Gro self-assigned this Aug 14, 2024
@T-Gro

Copy link
Copy Markdown
Member

@DedSec256 : Interface implementation can have attributes on it (not expressible in F#/C#, but in IL it is) and C# nullness metadata export makes use of it.

The nullness PR started to read it together with interface implementations, which will likely be the biggest conflict - let me know if you need any help with that.

Otherwise, once conflicts and CI are resolved, this should be good to be merged.

@DedSec256

Copy link
Copy Markdown
ContributorAuthor

This PR probably requires changes to the API, so some work is still in progress.

@DedSec256
DedSec256force-pushed the ber.a/lazyInterfaces branch from 633bed8 to 161af55CompareAugust 21, 2024 15:59
@DedSec256

Copy link
Copy Markdown
ContributorAuthor

In this PR, the interface implementations and their custom attributes have been combined into a single type InterfaceImpl, which should simplify both the usage of the API inside the compiler and its passing to the ILTypeDef constructor. Additionally, the type of the Implements property in ILTypeDef has been changed to InterruptibleLazy, as there are scenarios where it is necessary to check is metadata up to date, for which it is necessary to check whether the data has been computed or not (and there are already places in the AbstractIL API that expose lazy containers).

Comment threadsrc/Compiler/AbstractIL/ilmorph.fs Outdated
@vzarytovskii
vzarytovskii marked this pull request as draft August 30, 2024 13:19
@vzarytovskii

Copy link
Copy Markdown
Member

Converted to draft for now, lemme know if you need any help resolving issues/testing.

@DedSec256

Copy link
Copy Markdown
ContributorAuthor

Benchmarks update

MethodMeanErrorStdDevGen0Gen1Gen2Allocated
TypeCheckFiles - Old (latest main)6.212 s0.0654 s0.0611 s38000.000021000.000012000.00007.3 GB
TypeCheckFiles - New5.577 s0.0376 s0.0333 s31000.000014000.00005000.00006.74 GB

@psfinaki

Copy link
Copy Markdown
Contributor

Is this ready now @DedSec256? Nevermind one failing test, it's failing everywhere now.

@T-Gro

Copy link
Copy Markdown
Member

Alex @DedSec256 , can I move it out of draft now that all is passing?

@DedSec256
DedSec256 marked this pull request as ready for review September 17, 2024 16:03
@psfinaki

Copy link
Copy Markdown
Contributor

Thanks @DedSec256!

Sign up for freeto 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.

4 participants

@DedSec256@psfinaki@T-Gro@vzarytovskii