Saturday, 7 September 2013

Int / Int64 .Net Memory Allocations

Int / Int64 .Net Memory Allocations

I have a large application which averages about 30 mb/sec in memory
allocations (per performance monitor bytes allocated/sec measurement). I
am trying to cut this down substantially, and the source of the
allocations is not obvious.
To instrument things I have recorded my ETW traces for the CLR / GC, and
have exported the AllocationTick event, which records every time an
additional 100 kilobytes is allocated, and what the object type was that
was most recently allocated. This produces a nice size sample set. Three
object types account for 70% of my allocations, but they are a bit of a
mystery.
System.Int64 30%
System.Int32 28%
System.Runtime.CompilerServices.CallSite'1[System.Func'3[System.Runtime.CompilerServices.CallSite,System.Object,System.Object]]
12%
The dataset was ~70 minutes and a million events, so I am quite confident
in the numbers.
I am guessing this is somehow indicating that I am creating a lot of
pointers on the heap in some unexpected way? (this is an x64 application)
I use some linq and foreach loops, but these should only be creating
increment variables on the stack, not the heap.
I am running everything on top of the TPL / Dataflow library as well,
which could be generating these.
I am looking for any advice on what may be causing so many heap
allocations of int32/64, and perhaps some techniques to isolate these
allocations (call stacks would be great, but may be performance
prohibitive).

No comments:

Post a Comment