WPF Performance Suite - strange app behaviour - wpf

I am working on a project including WPF and OpenNI library with sensor usage. My application is very simple, I am getting hand points from sensor device and drawing two rectangles using data binding. When I'm launching my app, rectangles are drawn with very big lag, but strange thing is, when I start WPF Performance Suit, lag suddenly stops and application is working perfectly.
My question is, what WPF Performance Suit is doing to running application and how I can recreate the same behavior in code without using this program?
Thanks for any help.

Related

Codename One. Very slow work after build

I'm developing my project in Codename One. UI creating from code, not GUI Designer. Application consists of three forms, as navigation I use Hamburger sidebar. The emulator works fine, but the builded application works very slow. Application was tested on Android. The degree of brake application depends on the number of components in the form. The situation has changed a little after we changed android.asyncPaint to false, but the operating speed remains slow.
Above all, Hamburger sidebar animation works strange. At first shows previous form, and then only shows the selected form. But this problem is not as important as the terrible brake application.
In 9 our of 10 cases this is caused by developers using gradients which are notoriously slow. It can also be triggered by tiling very small images or too many layers of transparency.
We have a performance monitor tool in the simulator that exposes some of these issues. You should also watch this video which covers most performance issues: http://www.codenameone.com/how-do-i---improve-application-performance-or-track-down-performance-issues.html

What type of application starts faster: Windows Forms or WPF?

As far as I know WPF applications should work faster than Windows Forms applications because WPF applications use DirectX for rendering instead of GDI. But what kind of application will start faster: WPF or Windows Forms? Will the start time be roughly the same or will one type of application be considerably faster than the other?
I am not targeting any specific operating system.
Just to point out, in my experience the WPF renderer is in fact quite a bit slower than Windows Forms, despite using DirectX. This is because lots of tesselation and layout calculations are done on the CPU side, which effectively cancels out the performance gain of using the GPU.
Just google around for "WPF Slow" or "WPF Performance" and you'll find horrified developers shocked to learn their time and effort spent converting WinForms to WPF because of spin about GPUs has been wasted, as the result is slower than the original application.
However ... I will say this. WPF is far superior to WindowsForms in terms of styling, graphical capabilities, developer productivity (databinding), animation, look and feel etc. If performance really is an issue, on certain areas you can optimise. For instance, did you know that you can get an API to write directly to bitmap in WPF (see the WriteableBitmap class) to do GDI-like operations in memory? This is (surprisingly) about 20x faster than the WPF primitives for some operations.
Similarly you can use virtualization to improve the performance of datagrids etc. Telerik have an example of their grid scrolling 1,000,000 rows at interactive framerates.
In conclusion, have a think about what you are doing and see similar examples on the web. Are you doing real-time scientific dataacquisition and visualization or just a standard line of business app? Comparing similar examples to see what the framework is capable of will help you in your decision.
Update 2013 Q3
As an update, in various projects I'm now seeing faster and faster performance from WPF by moving anything and everything off the UI thread. E.g. leave the UI thread just for UI, do as much work as possible using Task Parallel Library or RX. Make everything async and don't block the UI thread while waiting.
Eliminate binding errors as these contribute to WPF performance problems.
You can move animations (e.g. wait or loading animations) onto a different thread for glitch-free animation. You can use render-to-bitmap when doing animated transitions.
The long story short? It is possible to get great performance from WPF applications (as well as slick UI) but you need to put in a bit more work!
I think the start time will be about the same.. I have created a few WPF applications recently and in some cases I think the initial loadtime is a bit slower than win forms, but it is not much and WPF more than makes up for it when the application is up and running
From my experience, I think WPF is quite reactive at start compared to winforms. However, the question is tough, especially considering that WPF can contain the other and vice versa.
I'd follow the philosophy of this article : http://joshsmithonwpf.wordpress.com/2007/09/05/wpf-vs-windows-forms/
WPF and Winforms are just not the same tool, and neither of them is supposed to substitute for the other ;)
The question has a lot of duplicates on this forum, please check here for a link and discussion and all of them : WPF vs. Windows Forms

Can you make animations multithreaded? How to improve animation performance

I'm using the FluidKit Cube Animation in my WPF application.
The animation is smooth when the application window is not in full-screen, but when the application is running in full screen (maximised - borderless window with no controls), the animation is not smooth.
I noticed the WPF application is hammering a single thread and only utilising one of the four cores of the CPU, memory utilisatio is low.
I'm wondering if there is any way of making the window multithreaded or just the animations multithreaded so the application can utilise more of the available hardware?
Are there any other ways to improve animations?
Ben
I will be really excited if someone tells me a UI thread in WPF can leverage multi core CPUs....
Jokes apart, GPU and CPU are different concepts sadly. Will it be controversial if I say "The hardware acceleration mode for WPF apps utilizes GPU's own hyper threading model instead of multi core CPUs."?
Although there are ways to improve animations such as animating Adorners using PresentationSource, Transforming Drawings and Geometries than Shapes, CompositionTarget.Rendering event, BeginStoryBoard.HandoffBehavior="Compose" etc. You will find all of these discussed in details over the internet.
Interestingly there is an old (very useful post) about multi core systems and their impact on parallel .Net frameworks such as PLINQ and WPF 3.0 etc. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/07562a10-17bd-44d3-975b-99ed02bd05de/
I hope this kicks off some very interesting brain storming from our very able StackOverflow experts....
Expectantly Waiting ... :-)
Try to avoid any effects and see how it works and totally avoid bitmap effects, because they force WPF to use software rendering which is not really good.
Suggest you to check out Performance Profiling Tools from Windows SDK. Good luck ;)

Creating high performance animations in WPF

I'm in a situation that requires many animations with effects like transparency to be applied but when there are about 10 of them running, my application slows down to a grinding halt! :(
I also, tried implementing a particle like effect using a frame by frame manual animation using the CompositionTarget.Rendering event, which changed an Image's Source property at a given framerate. Again, this works fine for the first few instances of the particles on the screen, but when more and more get added I need it to stay performance wise, which is always a tough ask for any application
I was wondering if anyone has any experience using pixel shaders in WPF for animations, or perhaps custom writeablebitmap's for animations?
I basically need to palm off most of the animation processing to the GPU if possible...
Thanks for any help you can give!
Cheers,
Mark
If you want performance you should think about using XNA instead.
Then, you can add the XNA project into your WPF app

WPF Architecture and Direct3D graphics acceleration

After reading the wikipedia article on WPF architecture, I am a bit confused with the benefits that WPF will offer me. (wikipedia is not a good research reference, but i found it useful). I have some questions
1) WPF uses d3d surfaces to render. However, the scenegraph is rendered into the d3d surface by the media integrated layer, which runs on the CPU. Is this true ?
2) I just found out by asking a question here that bitmaps dont use native resources. Does this mean that if i use alot of images, the MIL will copy each when rendering, rather than storing the bitmaps on the video card as a texture ?
3) The article mentions that WPF uses the painters algorithm which is back to front. Thats painfully slow. Is there any rational why WPF omits using Z-buffering and rendering front to back ? I am guessing its because the simplest way to handle transparency, but it seems weak.
The reason i ask is that i am thinking it wont be wise for me to put hundreds of buttons on a screen even though my colleagues are saying its directx accelerated. I dont quite believe that whole directx accelerated bit about WPF. I used to work on video games and my memory of writing d3d and opengl code tells me to be cautious.
For questions #1 and #3 you might want to check out this section of the SDK that discusses the Visual class and how it's rendering instructions are exchanged between the higher level framework and the media integration layer (MIL). It also discusses why the painters algorithm is used.
For #2, no that is most definitely not the case. The bitmap data will be moved to the hardware and cached there.
I tested that, I wrote two programs that show 1,000 buttons on screen, one in WinForms and one in WPF, both worked just fine.
I then pushed that up to 10,000 buttons, at that point the WPF app took a few seconds to start but run just fine, the WinForms app didn't start.
Win32 itself (and WinForms) isn't built for applications with hundreds of controls (believe me I wrote such an app), at some point it just stops working, WPF on the other hand, keeps working even if it slows down a bit at some point.
So, if you do need to put a lot of controls on screen WPF is your best bet (unless you want to roll your own UI framework - and you think you can do better than the entire MS perf team).
Also, WPF has many advantages other than graphics acceleration: richer graphics, drawing model that is easier to work with, animations, 3d and my personal favorite - amazing data-binding.
This will let you develop richer UIs faster - and I think that will make a much bigger difference than the painting algorithm used.
BTW, if you need to put hundreds of buttons on the screen this is likely to be a bad user experience and you may want to reconsider your UI design,

Resources