Reduce resident memory for VS tokenization and other caches #4590
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.

Addresses two memory problems in FSharp.Editor.dll:
ConditionalWeakTable. This keeps it alive as long as theDocumentIdis alive. This is too long - we don't need to strongly save all this all this information, we just need to save it for a sliding window of time usingSystem.Runtime.Caching.MemoryCachesolutions:
ConditionalWeakTabletoSystem.Runtime.Caching.MemoryCache. This PR uses a sliding window of 10 seconds per document to reclaim the data. No per-document data is held after the sliding window has expired (from what I've seen it typically takes about 30 seconds for the reclaim to kick in in normal conditions, it will be faster when we are low on memory)With one large file open this saves about 5% of the managed heap in active use, and about 7% of the managed heap after the sliding window has expired and all the data is reclaimed
With ~16 typical files opened this gave a reduction from 30MB to 6MB (active use) and 0MB (after sliding window has eexpired) of a total managed heap of around 120MB, i.e. about 25% of the managed heap.
Detail - single file
This is the usage now for this one-file scenario :
It replaces the sum of these two and a few more minor entries not at the top of the list
Detail - multiple files
For multiple-files, the new data is this:
Replacing approximately these four: