You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TcSymbolUseData[] accounting for 19.1 MB on the LOH #6084
This was after opening VS (dev16.0, with built-in VSIX) for about three minutes, slowly implementing a function in FSharp.Editor that uses FCS and Roslyn types for about 3 minutes. I say slowly because I code slowly 🙂
This is the TcSymbolUses ctor getting called 49 times, which is ~390k on the LOH each time. This is called by TypeCheckTask in the incremental builder:
Since in my scenario the large majority of these symbols are the same (in fact they would probably be the mostly the same in nearly every scenario), I wonder if there's an opportunity to cache them.
The way things are set up, we have to save some information after checking a file - and the information we save is a dump of all the symbol resolutions. For a medium-sized file I'd imagine this can be 400K no problem. The information is not particularly long lived - the next check of the file will make it irrelevant and the information will be collected. I think this architecture is OK - if we were trying to reduce the amount of re-computed information we would do that by making all of checking more incremental from parsing through to type-checking.
SO it's not a priori wrong to allocate this information, even in one linear array (note that pre-indexing the information or attempting to compress it is a waste of time since it is very often discarded). It does however feel odd if the CLR is somehow assuming it is long-lived.
Is the CLR applying the (in this case false) heuristic that all LOH objects are long-lived? If so I suppose we could artificially chunk the array though it feels, well, artificial. What's the minimum size on the LOH?
[ Aside: TBH much of this memory work would feel easier if the CLR just had a intrinsic allocation method that said "this object is big but transient", or magically worked that out. From a GC perspective there should be no real problem with allocating short-lived big objects apart from the data-copying costs involved, as the data should just evaporate immediately on next collection. ]
[<Struct>]
type TcSymbolUseData =
{ Item: Item
ItemOccurence: ItemOccurence
DisplayEnv: DisplayEnv
Range: range }
Looking at this
someone might want to turn ItemOccurence into a struct.
For the others:
DisplayEnv is generally a pointer to a shared object, not much to do there without too much work (well, ok, you could make it a uint16 indexing into an array of DisplayEnv)
Item is a pointer to more information about the item that is a big discriminated union that's going to be hard to reduce
Range is a struct already, and has recently got a tad bigger, not much we can do about that
If someone wants to look at this, it should be fairly easy to chunk the array allocated here based on sizeof<TcSymbolUseData> and a heuristic about LOH objects, it's pretty well encapsulated. The member AllUsesOfAllSymbols is only ever iterated, so you simply need to change consumers to iterate an array-of-arrays
type TcSymbolUses(g, capturedNameResolutions : ResizeArray<CapturedNameResolution>, formatSpecifierLocations: (range * int)[]) =
// Make sure we only capture the information we really need to report symbol uses
let allUsesOfSymbols = [| for cnr in capturedNameResolutions -> { Item=cnr.Item; ItemOccurence=cnr.ItemOccurence; DisplayEnv=cnr.DisplayEnv; Range=cnr.Range } |]
let capturedNameResolutions = ()
do ignore capturedNameResolutions // don't capture this!
member this.GetUsesOfSymbol(item) =
[| for symbolUse in allUsesOfSymbols do
if protectAssemblyExploration false (fun () -> ItemsAreEffectivelyEqual g item symbolUse.Item) then
yield symbolUse |]
member this.AllUsesOfSymbols = allUsesOfSymbols
member this.GetFormatSpecifierLocationsAndArity() = formatSpecifierLocations
(I must add: it is great to see this LOH-analysis work beginning to hone in on the actual data we need to save, rather than data that should never have been allocated/copied in the first place :) )
I might be off-base here, but the TcSymbolUseData[] is created from the capturedNameResolutions parameter, which is itself backed by an array at least capturedNameResolutions.Length long, right? If so, this means that the backing array for the list should be on the LOH as well, so we may need to go a step further back and chunk the way those name resolutions are generated in addition.
Ah, I see the caveat there now. Because CapturedNameResolution contains less data we can have more array elements before we hit the 85,000 byte limit, so we may not hit the LOH for that structure at all. Thanks for clarifying.
SO it's not a priori wrong to allocate this information, even in one linear array (note that pre-indexing the information or attempting to compress it is a waste of time since it is very often discarded).
This feels like a bit of a design smell to me. If we need to allocate ~390k of data very often (in this case, every 3-4 seconds), then it implies something needs to be cached. I was only working with two files and typing in one, and only adding a single function. I don't see why that requires
Activity
[-]TcSymbolUse[] accounting for 19.1 MB on the LOH[/-][+]TcSymbolUseData[] accounting for 19.1 MB on the LOH[/+]dsyme commentedon Jan 12, 2019
The way things are set up, we have to save some information after checking a file - and the information we save is a dump of all the symbol resolutions. For a medium-sized file I'd imagine this can be 400K no problem. The information is not particularly long lived - the next check of the file will make it irrelevant and the information will be collected. I think this architecture is OK - if we were trying to reduce the amount of re-computed information we would do that by making all of checking more incremental from parsing through to type-checking.
SO it's not a priori wrong to allocate this information, even in one linear array (note that pre-indexing the information or attempting to compress it is a waste of time since it is very often discarded). It does however feel odd if the CLR is somehow assuming it is long-lived.
Is the CLR applying the (in this case false) heuristic that all LOH objects are long-lived? If so I suppose we could artificially chunk the array though it feels, well, artificial. What's the minimum size on the LOH?
[ Aside: TBH much of this memory work would feel easier if the CLR just had a intrinsic allocation method that said "this object is big but transient", or magically worked that out. From a GC perspective there should be no real problem with allocating short-lived big objects apart from the data-copying costs involved, as the data should just evaporate immediately on next collection. ]
dsyme commentedon Jan 12, 2019
BTW this is the definition of
TcSymbolUseData:Looking at this
ItemOccurenceinto a struct.For the others:
DisplayEnvis generally a pointer to a shared object, not much to do there without too much work (well, ok, you could make it a uint16 indexing into an array of DisplayEnv)Itemis a pointer to more information about the item that is a big discriminated union that's going to be hard to reduceRangeis a struct already, and has recently got a tad bigger, not much we can do about thatdsyme commentedon Jan 12, 2019
To answer my question:
So we should chunk this thing I guess. Ugh how artificial. Fighting the memory manager is a PITA.
dsyme commentedon Jan 12, 2019
If someone wants to look at this, it should be fairly easy to chunk the array allocated here based on
sizeof<TcSymbolUseData>and a heuristic about LOH objects, it's pretty well encapsulated. The memberAllUsesOfAllSymbolsis only ever iterated, so you simply need to change consumers to iterate an array-of-arraysdsyme commentedon Jan 12, 2019
(I must add: it is great to see this LOH-analysis work beginning to hone in on the actual data we need to save, rather than data that should never have been allocated/copied in the first place :) )
baronfel commentedon Jan 12, 2019
I might be off-base here, but the
TcSymbolUseData[]is created from thecapturedNameResolutionsparameter, which is itself backed by an array at leastcapturedNameResolutions.Lengthlong, right? If so, this means that the backing array for the list should be on the LOH as well, so we may need to go a step further back and chunk the way those name resolutions are generated in addition.dsyme commentedon Jan 12, 2019
@baronfel Yes, that's correct (except that CapturedNameResolution is not a large struct so there will be less on the LOH).
baronfel commentedon Jan 12, 2019
Ah, I see the caveat there now. Because CapturedNameResolution contains less data we can have more array elements before we hit the 85,000 byte limit, so we may not hit the LOH for that structure at all. Thanks for clarifying.
cartermp commentedon Jan 12, 2019
FYI there is excellent information in our docs about this: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap
cartermp commentedon Jan 13, 2019
This feels like a bit of a design smell to me. If we need to allocate ~390k of data very often (in this case, every 3-4 seconds), then it implies something needs to be cached. I was only working with two files and typing in one, and only adding a single function. I don't see why that requires
cartermp commentedon Jan 13, 2019
But relatively speaking this is far less pressing than other issues filed
13 remaining items
Revert TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)
Revert TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)
Revert TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)
Revert TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)
Revert TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)
Revert TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)
Revert "TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)"
Revert "TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)"
Revert "TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)"
Revert "TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)"
Revert "TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)"