Dan Vogel
Dan Vogel

Reputation: 3938

Is WPF the reason my application is slow?

I am developing an application using WPF. The app runs full screen, and I need it to resize nicely no matter the monitor resolution. The graphic designer has designed beautiful images for the UI buttons, backgrounds, etc. Using an Illustrator plug-in, all the images have been converted to xaml files. I've added all these images into the application, and they look great. I am also using a lot of Grid layouts so that the screen can resize while still maintain the layout. All of this is displaying as desired, nothing looks stretched when run at a different resolution. However, screen transitions and UI interaction are slow.

I am wondering, is this is due to the heavy use of graphics? Am I using too many Grid layouts? But, I need the Grids so that I can have resolution independence.

The application runs fine on my development machine, but is very noticeably slower on machine with lower performance capabilities. Yeah, this is to be expected, but not to the degree that I'm seeing. My employer insists the application runs smoothly on these lower performance machines.

I've done some profiling of the application and it seem that what takes the most time is the display stuff (though I'm not sure I fully understand how effectively to use a profiler).

If it is the WPF that is causing the slowdown, what can I do to improve this?

Upvotes: 15

Views: 21856

Answers (6)

oysteinNy
oysteinNy

Reputation: 41

In general, WPF is perfoming much worse in drawing performance than Windows Forms, and native GDI or DirectX.

Yes, WPF is powerful in the sense you might make some neat stuff that is not supported in GDI, but it is more sluggish.

If you are having much drawing to do, and you want to support it on slow hardware, then WPF is not a good choice.

Upvotes: 4

Akash Kava
Akash Kava

Reputation: 39916

  1. Convert your XAML Vector Images of buttons into Transparent PNG Images. Path and Shapes are very heavy to render, calculate and resize. Mostly after deployment, the images never change its better to have them as raster then vector, unless you want to perform smooth animation of changing shape, size or other attributes.

  2. Grids are very costly layout managers as compared to Canvas, DockPanel. You can certainly think of replacing certain grids with DockPanel sometimes, but yes its not an easy fix it requires lot of brainstorming.

  3. Avoid Panel with Single Child. Try to reduce Visual Hierarchy.

  4. Use more of fixed size for buttons and such small elements, if you specify fixed sizes of children, it becomes easy for Panels to do layout processing.

Upvotes: 4

Thomas Levesque
Thomas Levesque

Reputation: 292345

If it is the WPF that is causing the slowdown

Probably not ;)

It is much more likely that it is your code that causes the slowdown. WPF is powerful, but you have to understand the core concepts to make it work well... You should have a look at this video from a PDC session, it provides lots of advice on how to make your WPF application faster

Upvotes: 5

Rubens Farias
Rubens Farias

Reputation: 57926

Well, this is a long shot: when I installed VSTS 2010 (and it uses WPF) it was very slow on a Windows 2008 server with enough CPU/memory, and very fast in a more modest notebook. We managed to disable hardware acceleration and it became notably fast into that machine.

Maybe you do want to try this configuration, as it is very simple: Visual Studio 2010 Beta 2 editor performance fix running on a virtual machine

Upvotes: 1

eduesing
eduesing

Reputation: 353

WPF performance depends heavily on the quality of the video card in the machine more that the processor/memory. Bad video card = bad WPF performance.

Upvotes: 2

itowlson
itowlson

Reputation: 74802

You can drill into which WPF activities are using up time using the Performance Profiling Tools for WPF. Assuming a heavy graphical load is causing the slowdown, this should give you some help as to what might need to be simplified (e.g. layouts) or removed (e.g. bitmap effects (these are a classic perf killer, though I don't want to prejudice your profiling!)).

Upvotes: 12

Related Questions