-
Notifications
You must be signed in to change notification settings - Fork 94
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
clear reader cache in background to prevent leak #295
Conversation
@TIHan Not sure the best way to unit test this. Perhaps an internal-only test hook |
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.
I get that this is an improvement, but it feels like we're just sort of throwing something at the wall and hoping it sticks here. Is there a way to tie this to the lifetime of the FSharpChecker instance used in tooling instead?
// Auto-clear the cache every 30.0 seconds. | ||
// We would use System.Runtime.Caching but some version constraints make this difficult. | ||
let enableAutoClear = try Environment.GetEnvironmentVariable("FSHARP_TPREADER_AUTOCLEAR_OFF") = null with _ -> true | ||
let clearSpanDefault = 30000 |
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.
What's the significance of 30 seconds compared with other values? When we consider that FCS re-checks frequently, how often would this re-allocate the large amount of data (400+ MB) on the LOH in normal usage?
Re testing: Yes, we would need to find an internal hook, similar to how I did testing before with the While this is to prevent memory leaks, it may not actually prevent it as each time we fetch assembly DLLs, we read a full I agree with @cartermp - it would be nice if we had some sort of interface that would allow us to hook into the lifetime of metadata from outside the TP (such as Roslyn). If that isn't feasible, then this may be the best we got. |
OK will add this
Yes, agreed. Will add separate issue for use of a big
Yes indeed, agreed. Perhaps we can discuss as part of #297. This issue really says "how can the TP know about the target context" - at the moment the only information communicated is the awful reflection hack for the list of referenced assemblies. |
@dsyme see here for issue on the |
@TIHan @cartermp I updated this so that it uses both a weak and strong cache
These fixes are still tactical. The 30 second timeout is just based on an estimate that that is
|
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.
I didn't have a good opinion on this, so I spoke to @heejaechang; this is a valid approach to the problem since there is no other way to handle the cache. In fact, Roslyn has similar thing in some circumstances.
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.
Approving as this is the tactical fix. We should file issues on this and the F# repo to tie this cache to the lifetime of the hosting FSharpChecker instance.
@TIHan This eliminates the long-term memory leak from the IL readers used by each TP implementation by clearing the reader cache every 30 seconds since last access (at the potential cost of re-computing readers).