-
Couldn't load subscription status.
- Fork 833
Optimizer: add a quick path before calling into freeInExpr #18895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/FSharp.Compiler.ComponentTests/Optimizer/NestedApplications.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| namespace FSharp.Compiler.ComponentTests.Optimizer | ||
|
|
||
| open System.Text | ||
| open Xunit | ||
| open FSharp.Test | ||
| open FSharp.Test.Compiler | ||
| open FSharp.Test.Utilities | ||
|
|
||
| module private Gen = | ||
| let nestedLetApps depth = | ||
| // Builds: let v1 = id 0 in let v2 = id v1 in ... in ignore vN | ||
| let sb = StringBuilder() | ||
| sb.AppendLine("module M") |> ignore | ||
| sb.AppendLine("let id x = x") |> ignore | ||
| sb.AppendLine("let run () =") |> ignore | ||
| for i in 1 .. depth do | ||
| if i = 1 then | ||
| sb.Append(" let v1 = id 0") |> ignore | ||
| else | ||
| sb.Append(" in let v").Append(i).Append(" = id v").Append(i-1) |> ignore | ||
| sb.AppendLine(" in ()") |> ignore | ||
| sb.ToString() | ||
|
|
||
| let nestedDirectApps depth = | ||
| // Builds: let res = id(id(id(...(0)))) in ignore res | ||
| let sb = StringBuilder() | ||
| sb.AppendLine("module N") |> ignore | ||
| sb.AppendLine("let id x = x") |> ignore | ||
| sb.Append("let run () = let res = ") |> ignore | ||
| for _ in 1 .. depth do | ||
| sb.Append("id (") |> ignore | ||
| sb.Append("0") |> ignore | ||
| for _ in 1 .. depth do | ||
| sb.Append(")") |> ignore | ||
| sb.AppendLine(" in ignore res") |> ignore | ||
| sb.ToString() | ||
|
|
||
| [<Collection(nameof NotThreadSafeResourceCollection)>] | ||
| type ``Nested application optimizer``() = | ||
|
|
||
| // Moderate depths to keep CI stable while still exercising the quadratic shapes | ||
| [<Theory>] | ||
| [<InlineData(100)>] | ||
| [<InlineData(1000)>] | ||
| let ``let-chains of nested apps compile under --optimize+`` depth = | ||
| let src = Gen.nestedLetApps depth | ||
| FSharp src | ||
| |> withOptions [ "--optimize+"; "--times" ] | ||
| |> asExe | ||
| |> ignoreWarnings | ||
| |> compile | ||
| |> shouldSucceed | ||
|
|
||
| [<Theory>] | ||
| [<InlineData(100)>] | ||
| [<InlineData(1000)>] | ||
| let ``direct nested application compiles under --optimize+`` depth = | ||
| let src = Gen.nestedDirectApps depth | ||
| FSharp src | ||
| |> withOptions [ "--optimize+"; "--times" ] | ||
| |> asExe | ||
| |> ignoreWarnings | ||
| |> compile | ||
| |> shouldSucceed | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this test on main to compare shows that the fix indeed works quite well. 5000 depth gives around 15 seconds Optimize phase on main, compared to below one sec here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is an edge case. Hard to tell how much this will improve real life build times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build fsc in Release, measure how long it takes, then recompile using the new artifacts.