Performance Discrepancy Between Templated Control and Direct Implementation
I encountered a performance issue while working on a project where I utilized two identical buttons with all properties set the same. The only difference was in the content: one button utilized a PathIcon inside a Viewbox, while the other utilized a templated control called SvgIcon, which also encapsulated the same PathIcon inside a Viewbox. Surprisingly, I noticed a significant time discrepancy between the two implementations, with the templated control taking longer.
Here's a breakdown of the performance observation:
- Button 1: Utilized a
PathIconinside aViewbox. - Button 2: Utilized a templated control called
SvgIcon, which also contained aPathIconinside aViewbox. - Both buttons had identical paths for their content.
Upon profiling the application, I found that the templated control (SvgIcon) alone consumed approximately 0.52 milliseconds more time compared to directly using PathIcon inside Viewbox.
When utilizing these controls within a ListView, the impact on performance becomes more noticeable.
I'm seeking insights into why there's a performance disparity between these seemingly similar implementations. Could anyone give potential reasons for this discrepancy and suggest optimizations to mitigate the performance overhead introduced by the templated control (SvgIcon) when used within a ListView?
Windows development | Windows App SDK
Developer technologies | XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.