-
Notifications
You must be signed in to change notification settings - Fork 123
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
FCS uses too much memory #158
Comments
I removed So I suspect there're more caches in FCS. |
I tried out the console app. However I don't see a leak as such - memory use rises but "Peak Working Set" stabilizes at around 400MB. So is the issue "VFPT/FCS uses too much memory on big solutions" or "FCS has a leak"? |
Yes, the memory use stabilizes after 5-6 runs. So, the issue is "FCS uses too much memory". I'm not sure about "big" solutions since it easily eats 2GB ram on the small VFPT one. |
From VFPT point of view we wanted FCS to allocate fixed amount of memory for each project. It may discard caches for projects but it certainly should not keep some "historical" caches for projects. As a result, subsequent |
OK, it would be good to identify a concrete memory bug or actionable saving. FCS uses memory for sure. How much it uses will be largely dictated by a combination of
I know you set the projectCacheSize parameter to 200 in order to improve cross-solution operations when there are lots of small projects. But always caching all projects (even 5-10) is to some extent asking for trouble - you're basically configuring FCS to say "memory be damned, cache everything!" :) Does the memory use go so high when you set the number of cached projects back to something small (or disable the cache)?https://github.com/fsprojects/VisualFSharpPowerTools/blob/1333806aa332bc63293fd45740b7c3c830dd5e35/src/FSharpVSPowerTools.Core/LanguageService.fs#L125 I don't think there are any other signficant hidden caches involved, but I may be wrong. |
@vasily-kirichenko I'm trying to repro a situtation where VFPT uses 2GB+ when opening its own solution. I did the following using the latest gallery published VFPT VSIX:
At this point memory use was around 1GB. I then started randomly typing into a few F# files and it went up a bit more, to around 1.2GB. I didn't do any debugging or the like. Based on this it feels like this solution should always stay within a 1.5GB memory budget, and if it doesn't (e.g. after renaming files, or changing other project options, or doing other VS activities or ...) then that would be considered a bug (either in VFPT or FCS) or would would at least motivate better caching mechanisms/policy. So it would be good to have a repro where this solution goes over 2GB (even with projectCacheSize=200=cache-everything)? thx |
Do we need to consider any of this for Xamarin Studio? On 10 Jun 2014, at 09:42, Don Syme [email protected] wrote:
|
@7sharp9 Eventually yes, though currently very large F# solutions are very, very likely to be using VS, and XS has fewer cross-solution features, and doesn't set projectCacheSize=200 AFAIK. |
@vasily-kirichenko I just read this comment (#158 (comment)). Agreed that FCS should not keep any out-of-date caches keyed on ProjectOptions (though I'm still unsure whether this is causing significant increased memory use) |
@vasily-kirichenko is right - there can be out of date entries in typeCheckLookup and typeCheckLookup2. I have a fix for this. |
(where colons are "private set" and "peak private set"). |
Fixed in 0.0.52, published, see d6a0644. @vasily-kirichenko Your test program now exhibits stable memory after one "w", but only if GC.Collect() is added after each "w"
There can still be "stale" entries in caches like typeCheck and typeCheck2 if projects are simply no longer in use (e.g. unloaded or renamed). Calling ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients will flush these, along with everything else. |
@vasily-kirichenko Could you report results for your repro above, when using 0.0.52? |
Yes, I'm doing the test right now. |
Great |
So, no improvements. Additionally, a strange effect added: after reloading the solution Highlight refs does not work at all or work partially like this: Then I execute Find all refs - nothing for about 20 seconds (0% CPU load), then some CPU load and refs appear. At the same moment Highlight refs started working. I'm not sure if this is FCS or VFPT bug. Need investigating. |
What actions does a "reload" perform w.r.t. FCS? Which of InvalidateConfiguration/InvalidateAll/ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients does it call? |
@vasily-kirichenko the "strange behaviour" feels like it was because there was a longish-running operation completing in the FCS queue such as a parse-and-check of the solution. A "Reload" won't cancel such an operation in the FCS design, nor do the Async<_> operations returned by FCS pay attention to cancellation tokens. |
On solution reload we call It'd be great if FCS exposes its queue length for debug purposes. |
FWIW, For step 2 in the repo above I repeatedly switched between these two:
and interleaved a Ctrl-, quick symbol find for a symbol in the VFPT source code e.g. 'HighlightUsageTagger'. This induces a project reloiad. With the current gallery VSPT installed there was definitely a leak. I'm 99% sure this is not the same as the "stale entries" problem fixed by @quasilord above. That wouldn't continue to leak when switching between two commits. It may not even be intrinsically an FCS problem - are there caches or other objects in VFPT which may be keeping handles to big objects? |
I took two VS snapshots while opening VFPT solution using PerfView. The first snapshot: load the projects into VS and wait for colorization to finish. Here the diff between the snapshots. To my surprise, Here is a stack trace which has quite a lot of samples. It seems FCS stuck inside XamlTypeProvider and couldn't release memories: I tried to remove XamlTypeProvider from VFPT solution, memory usage seems to stabilize after opening the solution. |
Here is the diff of exact scenario when XamlTypeProvider is removed. As you can see, the amount of increased memory (Total Metric) and the number of created objects (Count) is much smaller. @dsyme What are potential problems when FCS handles type providers? @vasily-kirichenko If you include |
The XamlProvider is never disposing its file watchers (which are registered in order to trigger invalidation): https://github.com/fsprojects/FsXaml/blob/master/src/FsXaml.Wpf.TypeProvider/TypeProvider.Helper.fs#L28 These file watchers keep the type provider instances alive, which in turn keep FCS resources alive and cause the leak. We should probably adjust FCS (and also the Visual F# Tools) to use a weak event handler when adding listeners to the "Invalidate" signals, which would make this kind of leak much, much less severe (leaking one FileWatcher per TP instance, instead of 200MB of data). |
I've tested the console on |
@dsyme That's very strange that Xaml TP does not implement |
Results are not very clear though. I added debug output to FsXaml and for 3 iterations it write the following:
The TP has been create 9 times (wow), but disposed only 8 times. So, FCS keep a reference to it? Why? And yes, the test console consumes memory in the same way as before. |
Is that output when using your console app, and is that calling ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients at the end to clear all caches (and hence all TP references)? |
This is the console output.
Now press 'c':
So, yes, the last instance is disposed if we clear the caches. |
After 10 iterations the console took 1GB RAM and it does not free any of it after Checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
GC.Collect()
GC.Collect() |
Is this with updated FCS (0.0.52) and XamlProvider (with your fix? is that published as a nuget package yet? See also this comment here: vasily-kirichenko/FsXaml@cff5b83#commitcomment-6631529) I noticed your console app still had a packages.config with referenced to FCS 0.0.50 I believe that Lexer data is just the lexer tables and is not significant. |
Yes, this was with FCS 0.0.52 (I just pushed a commit) and with fixed FsXaml. |
Have you tried the combination of FCS 0.0.53 and patched FsXaml? Does it make any difference? |
Tried 0.0.53 with patched FsXaml. Same behaviour. Now testing 0.0.54 |
One iteration + So, it's a great improvement! Cool. |
Wow, great news :). |
I'll update 0.0.52 PR to 0.0.54 and try to fix the failing tests. |
Could anyone merge the FsXaml PR please? |
Resolved variously in FsXaml and FCS |
See the VFPT issue fsprojects-archive/zzarchive-VisualFSharpPowerTools#474 (comment)
@dsyme suggested to check these caches first: https://github.com/fsharp/FSharp.Compiler.Service/blob/master/src/fsharp/vs/service.fs#L2235
It's a very serious problem: it causes VS to quickly occupy RAM at the point when everything becomes unusable (~1.8...2.5GB) due to continuous garbage collecting. In practice it means I have to restart VS every 0.5..1 hour during the day as I working on a solution with 50+ F# projects. Even intensive working on VFPT more than an hour is impossible.
I created a console with which I can quickly (a minute) check that the bug is fixed or not.
Please, fix it ASAP.
The text was updated successfully, but these errors were encountered: