Friday, 20 March 2009

Silverlight: SL3 Dropshadows are slow

This is probably no great surprise to anyone but bitmap effects have quite a significant performance hit on your CPU.

The following code is an example of how to apply a drop shadow

<StackPanel>
<Button Content="Drop Shadow Under Me" Width="200">
<Button.Effect>
<DropShadowEffect Color="Black" Direction="320"
ShadowDepth="25" BlurRadius="5" Opacity="0.5" />
</Button.Effect>
</Button>
</StackPanel>


So just be aware before you start apply dropshadows to every button / element on the page that it will slow your application down.



Just be considerate in your use (and always check your performance), especially since some effects (such as dropshadow) can easily be produced using more performant techniques.

4 comments:

Joeyw said...

Just wondered, is this with GPU enabled? Why would this be different to WPF?

chrishayuk said...

I'm afraid so, but I do think there is a bug in there.

CPU is about 2% with 70 buttons without GPU

CPU is about 13% with 70 buttons with drop shadows without GPU

CPU is about 45% with 70 buttons with drop shadows with GPU

As i said I think there is something going wrong there

Jaison Green said...

Yup yup,

Here is a post I made on the Silverlight.net forums. http://silverlight.net/forums/t/82131.aspx

Animating dropshadows is even worse.

Anonymous said...

Seema's Mix09 Session indicated that GPU support does not extend to PixelShaders - so it's only using software rendering..