dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.92k stars 786 forks source link

`Bug` Quadratic(?) compiler perf for huge nested expressions #12421

Open dsyme opened 2 years ago

dsyme commented 2 years ago

While investigating #12420 I noticed that one particular part of our optimizer seems quadratic for very large nested expressions made of nothing but function/method applications, e.g. M(M(M(M.....)))) and the kind of code that comes out of computation expressions.

The problem is already noted in our code, see permalink

This isn't critical but we should fix this sometime. It appears to be re-traversing expressions determining free variables.

T-Gro commented 2 years ago

I will check this one.

The behaviour is definitely still present. A simple single-file program consisting of a linear chain of primitive calls (like f(f(f(f(.. ) has the following timing differences between the --optimize- and --optimize+ switches:

image
T-Gro commented 1 year ago

( I have failed to change this, unassigning myself and making this available to anyone who wants to take an alternative look)