Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this slow WPF TextBlock performance expected?
    text
    copied!<p>I am doing some benchmarking to determine if I can use WPF for a new product. However, early performance results are disappointing. I made a quick app that uses data binding to display a bunch of random text inside of a list box every 100 ms and it was eating up ~15% CPU. So I made another quick app that skipped the data binding/data template scheme and does nothing but update 10 TextBlocks that are inside of a ListBox every 100 ms (the actual product wouldn't require 100 ms updates, more like 500 ms max, but this is a stress test). I'm still seeing ~5-10% CPU usage. Why is this so high? Is it because of all the garbage strings?</p> <p>Here's the XAML for the version that doesn't use binding:</p> <pre><code>&lt;Grid&gt; &lt;ListBox x:Name="numericsListBox"&gt; &lt;ListBox.Resources&gt; &lt;Style TargetType="TextBlock"&gt; &lt;Setter Property="FontSize" Value="48"/&gt; &lt;Setter Property="Width" Value="300"/&gt; &lt;/Style&gt; &lt;/ListBox.Resources&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;TextBlock/&gt; &lt;/ListBox&gt; &lt;/Grid&gt; </code></pre> <p>Here's the code behind:</p> <pre><code>public partial class Window1 : Window { private int _count = 0; public Window1() { InitializeComponent(); } private void OnLoad(object sender, RoutedEventArgs e) { var t = new DispatcherTimer(TimeSpan.FromSeconds(0.1), DispatcherPriority.Normal, UpdateNumerics, Dispatcher); t.Start(); } private void UpdateNumerics(object sender, EventArgs e) { ++_count; foreach (object textBlock in numericsListBox.Items) { var t = textBlock as TextBlock; if (t != null) t.Text = _count.ToString(); } } } </code></pre> <p>That consumes ~5-10% CPU according to Task Manager, or up to about 20% of one of the cores! Any ideas for a better way to quickly render text?</p> <p>My computer: XP SP3, 2.26 GHz Core 2 Duo, 4 GB RAM, Intel 4500 HD integrated graphics. And that is an order of magnitude beefier than the hardware I'd need to develop for in the real product.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload