Skip to content

discussion: impact of using exceptions on memory traffic to hold info in ConstraintSolver.ResolveOverloading #8260

@smoothdeveloper

Description

@smoothdeveloper

Just sharing an experiment: I'm running memory profiling on building of FSharpPlus test project (https://github.com/fsprojects/FSharpPlus/tree/master/tests/FSharpPlus.Tests).

The project is less than 4k lines of F# code, but it relies heavily on overload resolution and is a good stress test for that code in the compiler.

You can see the code has nothing special, the snapshots compared here are with "tracking of allocations" enabled between a snapshot taken early after starting the compilation and 1h+ in running.

I was interested in calls to ArgsMustSubsumeOrConvert and ArgsMustSubsumeOrConvertInsideUndo and how they are allocating ErrorsFromAddingSubsumptionConstraint for each argument of each method call being checked.

(ArgsEquivInsideUndo csenv cx.IsSome)

(ArgsMustSubsumeOrConvertInsideUndo csenv ndeep newTrace cxsln cx.IsSome)

(ArgsMustSubsumeOrConvertInsideUndo csenv ndeep newTrace cxsln cx.IsSome)

https://github.com/dotnet/fsharp/blob/master/src/fsharp/ConstraintSolver.fs#L2657
exception ErrorsFromAddingSubsumptionConstraint of tcGlobals: TcGlobals * displayEnv: DisplayEnv * TType * TType * exn * ContextInfo * range

ErrorsFromAddingSubsumptionConstraint being an exception (like many other types used in type checking), it carries significant weight in the base type, that is AFAIU not relevant for the purpose of carrying info, to eventually show error messages.

image

Notice that 500k of those exceptions are allocated for the purpose of resolving overloads, they are of course, very short lived, but I wonder if this doesn't have an impact in memory constrained scenarios like usage in tooling.

Is there any intuition about the impact of all the extra fields in System.Exception knowing that many of those objects are allocated during every method overload resolution?

To profile this, I've run debug version of fsc.exe compiled in this repository with this response file https://gist.github.com/smoothdeveloper/edbb90f8ea0cd9d6808d05fc528c375f

edit: after type checking completed, a total of 618250 ErrorsFromAddingSubsumptionConstraint have been instanciated / collected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions