Some times performance matters. GraphX have some common logical enchancements that works toward the performance improvement but sometimes that is not enough. In this article i'll show you some custom ways to improve performance a
little bit more.
Introduction into rendering performance
You can find a lot of articles over the internet about WPF overall performance and tips. So i'll say the basics.: the simplier object you want to draw - the more performant your App overall. I've tried to find the golden middle between the performance
and features so i've used Panel (same as Canvas in terms of performance) as layout area and Control as drawed object.
When you work with hundreds of objects it realy matters how you design templates or handle events (especialy WPF bubble events). That is why so important to performance-affected features optional.
Custom events control
have property called EventOptions
. Using this property you can configure which most usable events are listened or not. If you don't use any of them you can disable them to save a bit performance.
Custom visual templates
When using custom visual templates you should always hold in your mind how many vertices you want to draw. More complex the visual templates - more laggy graph will be. If you are oriented on the large vertices quantity (500+ i suppose) it is recommended to
choose your templates wisely:
- Always Freeze() any freezable objects such as pens, brushes or paths. This can save a lot of performance.
- Try to minimize images usage or try to find optimum image size to display.
- Try to minimize bindings and especialy converters usage. Converters can seriously blow the performance if they are used to create objects such as pens or brushes.
Other custom features
- GraphArea.GenerateGraph(_dataGraph, true, true) method introduces automatic unique ID assignment for vertex and edge data objects that misses it. If you assign IDs manually you can switch this feature off using method param. This can save graph generation
performance depending on graph size.