Why is everything so slow ?

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.




Answer this question

Why is everything so slow ?

  • Keith Henkel

    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.



  • Jesse Towner

    I'm using Windows XP Professional.

  • japt

    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



  • AnilK110285

    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).

  • Why is everything so slow ?