none
Why is everything so slow ?

    Question

  • The following code may not be a real-world application but it shows our main problems with WPF: slow rendering with many controls. I didn't find any hint to make those things faster. In this sample I've tried to use a bitmap effect. With this effect set, the application gets absolutely unusable - but even without bitmap effects the performance is poor (just try resizing the window - I used a fixed canvas size here to force redrawing).

    XAML:

    <Application x:Class="WindowsApplication2.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Window1.xaml"
        >
        <Application.Resources>
            <DropShadowBitmapEffect x:Key="MyDropShadowEffect" Direction="315" ShadowDepth="5" Opacity="0.6" />
            <Style TargetType="{x:Type Button}">
              <Setter Property="BitmapEffect" Value="{StaticResource MyDropShadowEffect}" />
            </Style>
        </Application.Resources>
    </Application>

    code to initialize the user interface with 400 buttons:

       public partial class Window1 : System.Windows.Window
        {
            public Window1()
            {
                InitializeComponent();
                Canvas canvas = new Canvas();
                int width = 20;
                int height = 20;
                canvas.Width = 25 * width;
                canvas.Height = 20 * height ;
                for (int row = 0; row < 20; row++)
                {
                    for (int col = 0; col < 20; col++)
                    {
                        Button button = new Button();
                        button.Width = width;
                        button.Height = height;
                        button.Content = col.ToString();
                        Canvas.SetTop(button, row * (height + 2));
                        Canvas.SetLeft(button, col * (width + 2));
                        canvas.Children.Add(button);
                    }
                }
                myGrid.Children.Add(canvas);
            }
        }
    }

    My machine is a 2.8 GHz Pentium, has an ATI 9600 TX, DirectX9.0c (Render Tier 2), Perforator shows 3 frames/s when I resize the window without bitmap effects and 0 with bitmap effects (screen update takes about 2 seconds !).

    I'm interested if others experience the same performance issues.

    Thursday, November 16, 2006 9:18 PM

Answers

  • Ah: our BitmapEffects are not efficient in V1. If you use a few of them on very small objects, they might be okay, but in general we recommend you to avoid them.

    400 items with effects will *not* be fast.

    This is a known limitation that we are working on for future releases.

    Friday, November 17, 2006 7:28 AM

All replies

  • Ah: our BitmapEffects are not efficient in V1. If you use a few of them on very small objects, they might be okay, but in general we recommend you to avoid them.

    400 items with effects will *not* be fast.

    This is a known limitation that we are working on for future releases.

    Friday, November 17, 2006 7:28 AM
  • I understand, that bitmap effects are slow - but even without them, using 400 controls is no fun at all (3 frames/s is not what I have expected in this sample).
    Friday, November 17, 2006 8:06 AM
  • I've sent this along to our perf team.

    We'll get you an answer.

    Thanks for the feedback.

    One question: what's your OS? If Vista, are you running w/ Glass?

    Monday, November 20, 2006 5:00 AM
  • I'm using Windows XP Professional.
    Monday, November 20, 2006 6:39 PM
  • What became of this issue?  I have almost the exact same problem.

    I am drawing a screen with 384 round buttons.  Each button is a custom control, that replaces the button control template with an ellipse, and a textblock.  No bitmapeffects.  The target is a Pentium 1Ghz (this is for an embedded environment) and no animation is required.  It takes about 2 seconds to draw the screen, with 1.3 seconds in the InitializeComponent() call.

    Since this is embedded, we can create the screen up front and just hide/display it.  The trade off is this solution increases our boot time and memory footprint.  I found some tricks that are buying me some little 10% - 20% performance improvements: like making the control template a style in App.xaml, instead of putting the contents directly into the control's XAML.  (Why does that help?)

    Kevin -- I'd love to know what you guys found in your research.  This is running on Windows Embedded standard.
    Tuesday, July 07, 2009 8:34 PM