26

I'm developing a .NET 4.5 WPF app and having UI rendering performance issues.

After some googling, I came across WPF Performance Suite page which describes exactly the tool I need - Visual Profiler. It allows to view WPF elements tree and analyze the contribution of each element to the total rendering time.

The only problem is that the page states that the tool is contained in Microsoft Windows SDK v7.1 which is targeting Windows 7 and .NET 4.0.

Since my app is for .NET 4.5 and I'm on Windows 8.1, I've installed Windows SDK for Windows 8.1. To my surprise, it doesn't seem to contain the WPF Performance Suite at all and that tool in particular.

Then, I've tried to install the WPF Performance Suite from this answer, but it works only with .NET 4.0 apps.

So, where do you get the WPF Performance Suite for .NET 4.5 apps?
Or, to be more general, how do you profile WPF UI rendering performance of .NET 4.5 apps to find out which elements in the tree have highest performance impact in complex UIs?

Community
  • 1
  • 1
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
  • Do you have these Start Menu shortcuts: Windows Kits | Windows Performance Toolkit | Windows Performance Analyzer and Recorder? That's what's I have, though I have the newer Win 10 SDK on my Win7 box. Perhaps this suite has changed names. – Chris O Nov 02 '15 at 00:09
  • @ChrisO: Yes, I have those shortcuts. I've tried to create metrics with Windows Performance Recorder with XAML Activity and XAML App Analysis additional profiles enabled. But when I'm opening the metrics in Windows Performance Analyzer, I can't see anything related to XAML metrics, only regular ones like Storage, Memory etc. Do you know how to use these two apps instead of the Perforator and the Visual Profiler to get WPF elements tree metrics? – Alexander Abakumov Nov 02 '15 at 13:21
  • No I don't, though the Help menu shows a link to [Windows Performance Toolkit Forum](https://social.msdn.microsoft.com/Forums/en-US/home?forum=wptkv5), you might have better luck there. – Chris O Nov 02 '15 at 14:57
  • @ChrisO: Get it, thank you! I'll give it a try! – Alexander Abakumov Nov 02 '15 at 17:37
  • Asking for recommendations on tools is off-topic on SO. You could rephrase the question into "How to profile WPF 4.5 UI performance" – Emond Nov 02 '15 at 19:24
  • @ErnodeWeerd: I've rephrased the question as you suggested, so you could cast back the close question vote, of course if one of them is yours :) – Alexander Abakumov Nov 02 '15 at 21:52
  • @AlexanderAbakumov - I see a link for WPF toolkit (including perforator) specifically for 4.5: https://msdn.microsoft.com/en-us/library/vstudio/aa969767(v=vs.140).aspx – Philip Rieck Nov 02 '15 at 22:25
  • 1
    @PhilipRieck: That's correct. But if you follow the [Windows SDK Download Page](http://go.microsoft.com/fwlink/?LinkId=200491) link in the **Installing the WPF Performance Suite** section, it will bring you to the **Microsoft Windows SDK for Windows 7 and .NET Framework 4** page, And after installing it, you can find that those tools are indeed for .NET 4.0 only. I don't know why it's marked as applicable to the .NET 4.5 apps. – Alexander Abakumov Nov 02 '15 at 22:50
  • Any update on this? The patch can't be downloaded anymore from the Microsoft website: https://download.microsoft.com/download/1/8/9/189A7832-49D8-4978-85E8-3DFFF44E6C04/WpfPerf_timezone_patch.msp – Coder14 Oct 26 '20 at 11:00
  • @Coder14 Which patch? – Alexander Abakumov Oct 26 '20 at 19:50
  • There should be a patch to make the WPF Performance Suite work on .Net 4.5, but the download link is broken. – Coder14 Oct 27 '20 at 08:16
  • @Coder14 WPF Performance Suite functionality seems to be covered by the new built-in Visual Studio features as described in [this answer](https://stackoverflow.com/a/33532790/3345644). Would it work for you? – Alexander Abakumov Oct 27 '20 at 22:16

2 Answers2

35

Eventually, I've found a tool that I was looking for and that was really helpful for me.

To get an idea of where exactly is the bottleneck in rendering your WPF layout, you want to:

  1. Install the Visual Studio 2015, if you don't have one yet :)
  2. Go to Debug -> Start Diagnostic Tools Without Debugging
    (NOTE: This seems to be changed to Debug -> Profiler -> Performance Profiler...).
  3. Check Application Timeline tool and hit Start in this view:

Tool settings

  1. When your app starts, do the actions causing issues you're interested in.
  2. Then hit Stop recording and you'll eventually get your elements tree with times spent for rendering every node. Then, you only need to sort it by Duration (total) and expand slowest nodes until you find the problem:

Result

In conclusion, it would much easier to correlate the nodes from tree above with your layout if you set names for your controls using the Name attribute like the following:

<TextBlock Name="OwnerContact">
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
1

As it turns out, later versions of Visual Studio have this built in, so right now with Visual Studio 2013, I can create a new profiler session by opening up Visual Studio, and from the top menu there is an Analyze drop down, just go to Analyze -> Profiler -> Attach/Detach to attach it to an existing process running in Debug mode (I seem to have to do this inside of another Visual Studio window or else its grayed out). But, side note: its really bad and not very intuitive...I would recommend using some nicer, commercial profilers instead because they are much simpler.

Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • I'd be more than happy to try a commercial profiler, if you could suggest one with WPF elements tree profiling :) I've tried ANTS, but it doesn't seem to provide such insights. – Alexander Abakumov Nov 02 '15 at 17:28
  • Regarding VS 2013 built-in profiling tools you've mentioned, there is [XAML UI Responsiveness tool](http://blogs.msdn.com/b/wpf/archive/2015/01/16/new-ui-performance-analysis-tool-for-wpf-applications.aspx). However, it's greyed out when I'm trying to use it with my project. AFAIK, this is because it works only with XAML-based Windows Store apps, but my app isn't the case, unfortunately. Or you've meant some other built-in tool? – Alexander Abakumov Nov 02 '15 at 17:33
  • @AlexanderAbakumov But AFAIK the ANTS profiler does indeed profile the .NET layer which should include WPF elements and trees, which includes also rendering methods and such things if that is what you are after, because it builds a tree of mehod calls that take the longest time to execute and shows it to you in a very nice graphical manner. Is this not the same thing as what you are after? Furthermore regarding built in tools, I think it requires a particular version of VS. I am using VS Professional 2013 – Alexandru Nov 02 '15 at 17:47
  • Yes, ANTS shows the huge hierarchy of method calls which includes tons of `OnMeasure` from different control classes like `UIElement`, `StackPanel` etc. The problem is that I have a complex UI and can't infer from these hot stack traces which exact element causes the performance issues. In fact, I've started to look for an WPF dedicated profiler after watching at the ANTS results, because I don't know how to correlate ANTS info to pinpoint a certain element in the WPF elements tree. – Alexander Abakumov Nov 02 '15 at 17:55
  • I'm using VS 2013 Ultimate and this is why I don't suppose it's due to the improper VS Edition. – Alexander Abakumov Nov 02 '15 at 17:57
  • @AlexanderAbakumov Have you tried using trial & error to pinpoint which UI element causes the longest delay time? So...just an idea but maybe you can comment out certain UI elements and try to pinpoint the hottest ones that way? Another thing to do too, is to use Stopwatch timers in your code to see which code section takes the longest to run something. – Alexandru Nov 02 '15 at 18:38
  • @AlexanderAbakumov I know you want to know which element is doing something wrong, but its better to go up the call stack and see what code you are invoking that does something to the user interface to make it take the delay time that its taking, and go backwards from there, as almost always the problem is not WPF but the code that invoked its controls :P – Alexandru Nov 02 '15 at 18:44
  • Alexandru, thanks for your ideas! :) The problem with the UI in this app is that it has many `Grid`s at different levels and too much standard controls in those `Grid`s. For now, I'm trying to decrease at least the app's start-up time which currently takes 50+ secs. Therefore, the only alternative to a dedicated profiler, as far as I can see, is commenting blocks of UI and assessing how much each of these blocks contributes to the performance. It's a lot of a guessing work and I hoped that I can avoid it with a tool or a technique that I'm currently unaware of. – Alexander Abakumov Nov 02 '15 at 22:05
  • @AlexanderAbakumov The only time I've seen C# code cause WPF UIs to be slow is when the code breaks UI virtualization. As an example of virtualization, you can think of it as only showing the data it needs to show, so if you have 1000 elements added to a list view but you can only show 10 of them at a time because of the height of the view, it will only render those 10. Sometimes code can cause this to stop working. I am not sure if this is the case for you or not, but I am just throwing out another idea :P – Alexandru Nov 03 '15 at 13:13
  • Alexandru: Awesome, thank you! I think I could give a try to virtualization during the layout redesign and see how it'll help to improve performance! – Alexander Abakumov Nov 03 '15 at 15:22
  • @AlexanderAbakumov Did you end up narrowing it down? – Alexandru Nov 04 '15 at 19:15
  • 1
    Alexandru: Yes :) I've eventually installed VS 2015 and used its new built-in analyzing tool called Application Timeline. Among the other things, It does exactly what I looked for: it shows the elements tree and time spent on each level during the layout process. That was extremely helpful to quickly pinpoint main issues, play with different solutions and analyze how they actually perform. – Alexander Abakumov Nov 04 '15 at 21:11
  • @AlexanderAbakumov Cool, I didn't know they added this. You should post that as an answer to your question! – Alexandru Nov 05 '15 at 19:24
  • 1
    Alexandru: I've already posted it - see my answer below :) Please feel free to upvote or let me know what I can do to make it better. – Alexander Abakumov Nov 05 '15 at 22:35
  • @AlexanderAbakumov Nice work & excellent find; I will remember to keep an eye out for this utility the next time I have any WPF issues. – Alexandru Nov 06 '15 at 02:11
  • Alexandru: Glad it's helpful! Thank you for your ideas. I think you may add those of them in the comments to the answer, since they give the great starting points in case one has no dedicated tool. – Alexander Abakumov Nov 06 '15 at 12:22