'External Code' taking up most of my CPU?

Started by
13 comments, last by Adam_42 8 years ago

I'm guessing Garbage Collector. With a callstack so deep, the GC may end up deciding it needs to run; whether because of heuristics, or because it actually needs to (running out of heap space?).

Is there an option for VS to show you the actual external code? I think it's a setting somewhere. Maybe this setting also affects the profiler so you can see what External Code means.

From MS:

The [External Code] entries indicate time spent in the platform and runtime on behalf of our code doing work such as rendering the UI, initializing the app, and garbage collection.

Advertisement

Is there an option for VS to show you the actual external code? I think it's a setting somewhere. Maybe this setting also affects the profiler so you can see what External Code means.

In vs2013 at least, it does indeed affect the profiler. (There's also a toggle in the main profiler summary view that lets you switch between "all code" and "just my code"). Running the sample code I posted above results in this (first number is inclusive samples):


PerfTest.Program.Main(string[]) PerfTest.exe 177 0 100.00 0.00
    System.Linq.Enumerable.ElementAt(class System.Collections.Generic.IEnumerable`1<!!0>,int32) System.Core.ni.dll 177 10 100.00 5.65
        System.Collections.Generic.Dictionary`2.ValueCollection.Enumerator.MoveNext() mscorlib.ni.dll 141 141 79.66 79.66
        [Unknown] [Unknown] 26 26 14.69 14.69

The implementation of ElementAt calls MoveNext n times to locate the item at index n (unless the IEnumerable can be cast to IList, which Dictionary can't). So it's a slow way of iterating through a dictionary's values.

Not sure what the call to [Unknown] is in ElementAt. Maybe that's the gc kicking in.

Could you just change this

for (int i = 0; i < blobs.Values.Count; i++)
{
value += blobs.Values.ElementAt(i).a;
}
to
for (int i = 0; i < blobs.Values.Count; i++)
{
value += blobs.Values.a;
}

Sorry for the late reply, today has been a busy day at university.

I made the changes you guys recommended, namely, switching out the elementat call for an array access and moving the BoundingBox 'new' call outside of the loop. These two changes have indeed helped increase performance but it still isn't up to the point I was thinking voxel raycasting would be at. I have the following output on the profiler now, the GIWorld.Update call doesn't even show up on the list, I'm looking into how to get the External code portions to show more detail though.

http://imgur.com/dLwm01m

Additionally, it seems there's a bug in the actual raycasting code, as a result of which the results are incorrect. I was hoping to use voxel raycasting on the CPU to do an additional low resolution indirect lighting bounce and then upload that to the GPU for compositing, which is beginning to seem like a not too great idea.

Instructions to show you what's in the external code section: http://stackoverflow.com/questions/33482789/external-code-in-vs2015-profiler

When you have the diagnostic view up, look for a dropdown that says "Filter View". It's in the area below the graph but above the listview. Click the dropdown and check the "Show External Code" checkbox.

Also see https://msdn.microsoft.com/en-us/library/dn971856.aspx

This topic is closed to new replies.

Advertisement