views:

82

answers:

2

I have a Silverlight application where I periodically load more data and add it to the page as UserControls. I load about 25 objects in one set and create one UserControl for each object.

This ends up taking quite a bit of time! Loading 25 objects takes 50-150ms purely in the UI. This makes my animations rather jerky, which is very much undesirable.

Is there any way to speed up the loading of the UserControls? I would rather not add some sort of buffering layer which loads X items per second. I would also rather not preload some large buffer of UI objects, which I would zombiefy/reuse based on how much data comes in. At the moment, however, I can't think of any other options.

The UserControls themselves are rather simple and I am very surprised that they load so slowly. Basically, I just create them (doing nothing expensive in the constructor), set the DataContext and add them to their parent canvas.

Is it supposed to be that slow? Is there something obvious I could be missing here? Can I somehow decouple this from the animations timing? I guess not - the UI is almost certainly single-threaded.

A: 

I'm not totally sure how your animations tie into creating the UI objects so maybe I'm missing something. Just to be upfront, the only solutions I know of are things you've said you don't want to pursue. I would create the new UI objects before starting the animation with their visibility set to collapsed. You could then have the animation modify the UI elements Visibility at the appropriate time to make them Visible. There's an overhead when creating UI objects (the 50-150ms you mention doesn't sound totally out of line, without knowing what the objects do) that you can't get away from. You might make sure your UI objects aren't doing any unnecessary work in the constructor or Loaded event handler. My general thinking on performance issues is that you need to test, not theorize, so I'd try multiple options and see which gives you the desired performance.

James Cadd
A: 

After a long time of trying various solutions on various projects, the only thing I can say is that it really is that slow. I have not found any other solution other than just plain creating as few objects as is humanly possible, all the time, everywhere.

UI object creation is amazingly slow. It seems to be a sad fact.

Sander