Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.Run is the top CPU consuming function in my application; what can I optimize?

My WPF application has a feature whereby it renders a large number of images in the background while updating the UI whenever a new image is ready.

Profiling this process has shown that Application.Run is the function doing the most work, at 43%, with the "second most expensive" spot shared by three graphics APIs, each at 6%.

What might I be doing that would cause so much time to be spent in Application.Run? It seems that the core of this method is running the main dispatcher for my app, but that doesn't help me figure out what it is that the dispatcher is doing so much. Can I get a more fine-grained profile?

Note: I mean System.Windows.Application.Run.

like image 916
Roman Starkov Avatar asked Feb 01 '12 11:02

Roman Starkov


1 Answers

Turns out that the Visual Profiler (part of the WPF Performance Suite) can provide a more detailed break-down of the CPU usage:

CPU usage breakdown

This shows that half of that unexplained CPU usage is down to the rendering thread (so perhaps I should update the UI less frequently), and much of the rest is spent in my Invoke callback (which is unavoidable in my case).

like image 168
Roman Starkov Avatar answered Sep 22 '22 12:09

Roman Starkov