-
Notifications
You must be signed in to change notification settings - Fork 825
Use new Cache api in various places #18872
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
Draft
majocha
wants to merge
11
commits into
dotnet:main
Choose a base branch
from
majocha:cache-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f96890a
use new cache api
majocha 0bd3211
fix comment
majocha d0baf11
can we get away with it?
majocha 3c7d950
ordered copilot to fix it, let's see
majocha ff33652
wip copilot fix
majocha 23dbf1e
Merge branch 'cache-2' of https://github.com/majocha/fsharp into cache-2
majocha 8d20904
wip
majocha b543788
wip
majocha f8ea068
restore
majocha df50139
remove test cache size overrides
majocha 476dcb6
improve
majocha 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
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
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
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ open Internal.Utilities.Collections | |
open Internal.Utilities.Library | ||
open Internal.Utilities.Library.Extras | ||
open FSharp.Compiler | ||
open FSharp.Compiler.Caches | ||
open FSharp.Compiler.AbstractIL.Diagnostics | ||
open FSharp.Compiler.AbstractIL.IL | ||
open FSharp.Compiler.AttributeChecking | ||
|
@@ -36,6 +37,10 @@ open System.Collections.ObjectModel | |
|
||
let OptimizerStackGuardDepth = GetEnvInteger "FSHARP_Optimizer" 50 | ||
|
||
let getFreeLocalsCache = | ||
let options = CacheOptions.getReferenceIdentity() |> CacheOptions.withNoEviction | ||
WeakMap.getOrCreate <| fun _ -> new Cache<_, _>(options, "freeLocalsCache") | ||
|
||
let i_ldlen = [ I_ldlen; (AI_conv DT_I4) ] | ||
|
||
/// size of a function call | ||
|
@@ -2898,10 +2903,11 @@ and OptimizeLinearExpr cenv env expr contf = | |
|
||
let (bindR, bindingInfo), env = OptimizeBinding cenv false env bind | ||
|
||
OptimizeLinearExpr cenv env body (contf << (fun (bodyR, bodyInfo) -> | ||
OptimizeLinearExpr cenv env body (contf << (fun (bodyR, bodyInfo) -> | ||
// PERF: This call to ValueIsUsedOrHasEffect/freeInExpr amounts to 9% of all optimization time. | ||
// Is it quadratic or quasi-quadratic? | ||
if ValueIsUsedOrHasEffect cenv (fun () -> (freeInExpr (CollectLocalsWithStackGuard()) bodyR).FreeLocals) (bindR, bindingInfo) then | ||
let collect expr = (freeInExpr (CollectLocalsWithStackGuard()) expr).FreeLocals | ||
if ValueIsUsedOrHasEffect cenv (fun () -> (getFreeLocalsCache cenv).GetOrAdd(bodyR, collect)) (bindR, bindingInfo) then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives a modest 20% hit ratio in tests. May or may not help somewhat IRL but needs benchmarking. |
||
// Eliminate let bindings on the way back up | ||
let exprR, adjust = TryEliminateLet cenv env bindR bodyR m | ||
exprR, | ||
|
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
Oops, something went wrong.
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.
Are these caches going to be cleared when asking FCS to clear its caches?
Uh oh!
There was an error while loading. Please reload this page.
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.
Currently not, I think since they're weakly attached to higher lever stuff, they'll just get GC'd with it. I captured some telemetry and the caches get disposed quite often during the test run.