Search
Sunday, September 07, 2008 ..:: Blendblog.net ::.. Register  Login
 Bloggers Minimize

 Print   
 Sponsors Minimize

 Print   
 Users Online Minimize
Membership Membership:
Latest New User Latest: mack1050
New Today New Today: 0
New Yesterday New Yesterday: 0
User Count Overall: 13

People Online People Online:
Visitors Visitors: 27
Members Members: 0
Total Total: 27

Online Now Online Now:

 Print   
 Welcome to blendblog.net! Minimize

If you are a developer or designer who is creating cutting edge user interface experiences using Microsoft Expression Blend you've just found a great resource!  The purpose of this site is to share our experience with this brand new product.  As with any new piece of software there is a ton to discover.  Bugs will be revealed and workarounds discovered, hopefully this can be a resource to share in the discovery process!

While this site will focus largely on Expression Blend, it will also encompass WPF, Visual Studio, Silverlight, and other .net 3.5 technologies as they relate to the creation of great software.

Please login using your Microsoft LiveID or register a new account.  Doing so will let you comment on any of the blog entries on the site.  We look forward to helping you in your endeavors as well as you helping others in theirs!  We'd love to have more bloggers on our site...if you are interested please register and contact us!


 Print   
 Massive listbox performance improvement and loading resources from resource dictionaries Minimize
Location: BlogsSean Cullinan    
Posted by: Sean Cullinan 5/23/2008 2:16 PM

I've been busy showing off the work we've been doing in WPF to our clients, both in the UK, and in Las Vegas at a tradeshow.  We had ramped up to these events and while we had a very nice, working application the performance was just terrible.  We were hoping SP1 of the .net framework 3.5 would fix things, but when we installed Beta 1 of this it didn't fix our performance headaches.  Off of the tight deadline I was able to do some code profiling and found my problems.

To sum things up, any time you are loading up a resource dictionary you will take a performance hit.  Do a search in your code ASAP for "= New Uri" across your application and ask yourself "when does this get called?"  If its called frequently consider caching the resource at the module or global level of your application and re-using the copy in memory, your application will run much faster for it.

My listboxes were using a multi-valueconverter to determine which image to display in the template next to the text for the listbox.  What I discovered was that the convert method of the multi-valueconverter was creating a new object of a utility class that I have to work with a large resource dictionary containing vector images.  On the constructor for that class I was calling the following code:

        mobjResourceDictionary = New ResourceDictionary
        mobjResourceDictionary.Source = New Uri("pack://application:,,,/UtilLib;component/VectorImages.xaml")

So for each item in the listbox it was loading this resourcedictionary.  That was my bottleneck.  My solution was to declare my utility class at the module level in my IMultiValueConverter class and on the constructor create the new object of the utility class, then use that object in the convert routine.  Since it only loads the resource dictionary one time (at load time of the app in fact) the render of the list box went from taking 3 seconds with 200 items to under a second (instantaneous to the user).  Further, because I am using a virtualizing stack panel in my listbox template, scrolling the listbox is now smooth whereas in the past it was choppy.

I went through my application and noticed several other places where I was loading up resource dictionary objects.  I decided that I would avoid this at all costs, loading them once preferrably when my splash screen was up and then re-usuing the global resourcedictionary objects that I create at that time across my application.  Once I did this I fixed a ton of performance problems.  For instance, I had code that was loading a resource dictionary up in my gotfocus/lostfocus events of a control I wrote that was drastically slowing things down. 

While it seems so obvious now, a lot of the sample/demo code out there arbitrarily loads resources up.  In practice this SHOULD NOT BE DONE frequently, you should load your resource dictionary up and startup and re-use your object in your app to keep it in memory.  Taking this approach has drastically increased the speed of my application.

Sean

Permalink |  Trackback

Your name:
Title:
Comment:
Add Comment   Cancel 

  
 Search Minimize

 Print   
 Archive Minimize

 Print   
 Blendblog Survey Minimize
Our next client application will be written using:




Submit Survey  View Results

 Print   
 Sponsors Minimize

 Print   
Copyright 2008 by blendblog.net   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2008 by DotNetNuke Corporation