Performance Discrepancy Between Templated Control and Direct Implementation

Muthu S 20 Reputation points
2024-05-24T05:00:57.4466667+00:00

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 PathIcon inside a Viewbox.
  • Button 2: Utilized a templated control called SvgIcon, which also contained a PathIcon inside a Viewbox.
  • 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?image (1)

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
793 questions
C#
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.
11,005 questions
XAML
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.
814 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.