Quickly speed up Silverlight 3 graphics with the GPU enhancements

My last two posts have me drawing over 2,000 graphics objects onto the Virtual Earth Silverlight control. (Each pushpin represents an airport)

map

One side effect of managing all these objects on screen was high CPU usage:

cpu1

So this application is pushing my Quad Core machine pretty hard. ( On my dual core laptop, the utilization is about 85% )

Therefore a really easy way to fix this is to use the GPU enhancements in Silverlight 3. By explicitally letting my powerful Garphics card take care of this painting, I can significantly reduce my load.

First I add this property to my Silverlight control:

EnableGPUAcceleration=”true”

For example:


<body>

    <form id="form1" runat="server" style="height:100%;">

        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div  style="height:100%;">

            <asp:Silverlight ID="Silverlight1"  EnableGPUAcceleration="true"  EnableFrameRateCounter="true" runat="server" 

            Source="~/ClientBin/FlightTracks.xap" 

            MinimumVersion="3.0.40307.0" 

            Width="100%" Height="100%" /></div>
</form>

</body>

Then simply add a new BitMApCache object to each Image:


Image image = new Image();
image.CacheMode = new BitmapCache();
image.Source = bmp;

That results in the following low CPU utilization:
cpu2

Advertisements

2 thoughts on “Quickly speed up Silverlight 3 graphics with the GPU enhancements

  1. That’s quite a major improvement. I didn’t realise that silverlight used software decoding by default during rendering.

    Is there any circumstance where you would not want to set EnableGPUAcceleration?

  2. Turning on this feature will start using system resources whether or not it is needed, which is probably why it is off by default.

    So for a simple custom button implemented in Silverlight, you should keep it turned off.

    In my example I actually experimented by applying the BitmapCache object to different levels to determine optimum performance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s