2

I have a scenario that I need some good solid advice on. The question is really about speed of WriteableBitmap vs. images in IsolatedStorage on the Windows Phone.

I have an app that displays a UserControl (#1) which is a little graphically heavy. When the user swipes it, it transitions in a push-left type of transition to bring in a new UserControl (#2) which is also a little graphically heavy. If the user swipes the other way, control #1 is brought in in the same type of push-transition, this time from the right.

What I do today is take a snapshot of #1, load #2 off screen and take a snapshot of it, put both side-by-side in a Canvas control and animate that control either left or right. One of the reasons I don't just use the controls and animate them is they may have animation that starts when they are loaded - my current technique allows me to capture a screen shot of pre-animation and post-animation, depending on which direction they go in.

What I'm wondering, however, if it would be better/faster to just do the above the first time and send the writeablebitmap to IsolatedStorage with Extenstions.SaveJPEG and just use that instead in subsequent tranistion animations.

Would load/render/WriteableBitmap each time generally be faster or load jpeg from IsolatedStorage be faster each time? I see that the Transitions control in the SDK doesn't really do either of these, so I'm open to suggestions that are different that also might improve performance.

Todd Main
  • 28,951
  • 11
  • 82
  • 146
  • I'd appreciate it if you could update us on any investigation you do on this. I have a similar problem, and am curious what the best approach is. – Steve Jun 29 '11 at 19:41

1 Answers1

3

I expect this to be very depended on the hardware and application. So it is pretty hard to give an answer based on this input. It doesn't look to hard to test (on actual hardware and with the actual application) so my advice is to build both and test.

The applications I have been working with use both approaches and to be honest I haven't noticed much difference.

Also you might try and enable bitmap caching on the controls. This will give you a writeable bitmap implementation that is very fast.

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115
  • That is what I see in most of the code I am using for full screen transitions (Pivot and Panorama) – Emond Jun 29 '11 at 12:31
  • I've read through the link as well as other items on bitmap caching and have some questions: **1)** So if I'm on UserControl #3 and #2 and #1 are effectively garbage collected, will their bitmap caches persist so that if I go back to them, they will be fast to reload? **2)** Is the bitmap cache of the pre-animation states or the post-animation state? – Todd Main Jun 29 '11 at 17:52
  • As far as I know both cases you mention are excellent examples of when not to use bitmap caching. The build-in Bitmap cache is best for controls that do not change in any other way than by transformations that can be done by the GPU (translation, rotation, scale, skew). As soon as the original control changes (by animation other than the previously mentioned transformations or getting garbage collected or any other invalidation) the cache will be invalidated. So it can even work against you because the continuously rechaching. Disclaimer: I know this for WPF and SL, I am not sure for WP7 – Emond Jun 29 '11 at 19:27
  • Transformations such as sliding in or out of view are fine. Have a look at the original implementation of the Pivot control and Panorama control: http://phone.codeplex.com/SourceControl/changeset/view/55041#914238 – Emond Jun 29 '11 at 19:29
  • So for those types of animations that happen on load of user control, the recommendation is just to use BitmapCache. For those that have other types of animation, such as `PointAnimation`, the recommendation is to keep on doing what I'm currently doing? – Todd Main Jun 30 '11 at 00:08
  • If you are using the PointAnimation to move a control you should use Bitmapcache. If you are using PointAnimation to manipulate a line segment then you shouldn't. – Emond Jun 30 '11 at 04:04
  • @Otaku, I noticed you checked this answer. Did you test any of the suggestions? – Emond Jun 30 '11 at 17:23
  • I did bitmap caching on non-animated usercontrols and those with only simple animations. For all others, I'm using my original method. – Todd Main Jun 30 '11 at 17:46
  • @Otaku, did it improve performance? Others might benefit from your experiences if you add them to the question/answer. – Emond Jun 30 '11 at 18:58
  • The bitmap caching *felt* like it helped run faster, but I did not programmatically test it. – Todd Main Jun 30 '11 at 19:21
  • Just to follow up on this, I converted everything to the new 1.1 SDK and ran a performance test on both scenarios. They were about the same. So I tested a modified version of IsoStorage solution where as soon as a new page comes into view, a `ThreadPool` is launched to load the saved image from iso for the *next* page into a `WriteableBitmap`. So if I'm going from page 1 to 2, as soon as I reach 2, a `ThreadPool.QueueUserWorkItem` is launched to pull out the image for page 3 and then `Dispatch.BeginInvoke` loads it into a WriteableBitmap variable. There is definetely a performance increase. – Todd Main Oct 09 '11 at 20:05