WPF performace tips

* For better performacne, use DrawingContext.DrawGeometry with a StreamGeometry instead of other draw method like DrawingContext.DrawLine etc. StreamGeometry is a pretty light-weight object.

* Set a smaller value (<60) of 'System.Windows.Media.Animation.Timeline.DesiredFrameRateProperty' on amination objects to improve animation performance if applicable. In most cases, the default frame rate 60 is just too many.

* From performance perspectve, considering that scenario that calling DrawingContext.DrawXX methods passing a pen parameter inside a loop, sharing the pen instance is less sufficient than creating the pen instance each time inside the loop.

This is because Pen is a freezable resource. Tests found: Use a FRONZON shared pen instance is the best in performance.

The conclusion is: Froze a freezable object as possible as you can.

* Two ways to create DrawingContext: DrawingGroup.Open DrawingVisual.RenderOpen. The latter DrawingContext provides better perf usually.

WPF uses retained way to render. The call to DrawingContext.DrawXX just generates the rendering instruction. The real rendering is postponed to DrawingContext.Close.

你可能感兴趣的:(WPF performace tips)