10 Quick Real-World Windows Phone Developer Performance Tuning Tips
Join the DZone community and get the full member experience.Join For Free
let us begin by … oh heck; we are trying to cut the fluff & fine-tune our windows phone applications, right?
so, here goes:
- app startup:
- network calls:
- isolated storage:
- performance tools:
- low-cost device optimization:
- common sense:
this should be common knowledge .. windows phone handles jpgs much quicker than pngs. so, unless we need transparency, let’s stay away from unnecessary pngs. next comes the resource vs content dilemma. resources add bulk to dll and content adds files to the xap. larger dll will add to app startup time; but render images quicker than first-time file access for contents. there is no easy thumbrule here; depends on what fits your app. i personally see better performance with a resource if app startup time isn’t being hindered much, and if using an image many times as panorama/page backgrounds. much more details here .
if the xaml page has data binding (specially in case of panoramas), i find it odd to provide context to xaml on page_loaded event. why not on constructor, if possible? not that constructors need to be bloated; but why wait for the loaded event if you can data bind right away and allow rendering? even if i am firing off heavy operations on background thread, i prefer data binding (with cached data) before anything else. data binding on loaded/navigatedto should be reserved for times when on back navigations, you truly want updated data source or two-way binding.
let us do everything possible to not hinder the rendering of the first frame page. shoot for minimal code in app constructor/launching; similarly in mainpage with simple xaml layout. progress indicators are great after first page renders; consider if the splashscreen is really needed. if data binding needs dynamic data, consider overlaying the page contents with some progress indicators until ready. if binding to static data but fetching fresh data in background, i think it’s ok to load page and warn the user that he is looking as stale data. great article here .
let’s make sure we understand the subtleties of threading and never ever block the king, the ui thread. composition threads handle animations and off-load work to gpu; so not suitable for us to do any more heavy-lifting. let’s make friends with the background thread/worker ( here ‘s how) and push off anything we can to this guy. until async-await become more mainstream, let us be diligent about marshaling stuff back to the ui thread through shared variables or dispatcher.begininvoke().
4 thumbrules i try to follow: through background thread/httpwebrequest. grab more in one call, instead of making many api calls. cache anything possible. check for connectivity & degrade gracefully.
if not close to 90mb memory restriction, i try to minimize hits to isolated storage for disk access. it’s ok to have a giant object & serialize/deserialize in one go. and remember, encryption/decryption is expensive; so reserve for the super-sensitive stuff.
let’s use what’s at our disposal – the windows phone performance analysis tool ( here ) for detailed performance walkthrough and the frame rate counters to figure out the bottlenecks. i try to watch out for huge memory footprints, like a high resolution image loaded in memory, but displayed as a small picture.
yes, we would love our apps to be flashy; but complex & nested xaml comes at a price .. so let’s try to keep our layouts simple. panoramas render all panels with data binding at once, which can take a toll on memory. deferred panel loading and background bitmap as resource are things i try doing when using panoramas, or considers pivots when possible. things like toolkit hubtile controls also add a little bulk; make sure to stop animations on non-visible areas. maps & webbrowsers are expensive too; consider if the corresponding tasks fit what you are trying to do.
taking the marketing fight downstream was needed; hence comes the so-called lower devices with 256mb ram. for the most part, we should be fine if following performance best practices for regular windows phone devices. just a few additional things for us to keep in mind: let’s not use background agents (can’t depend on them anyways since they can be disabled by user or overuse); watch the 90mb memory footprint; no looping backstack navigation; use the 256mb emulator for lowest common factor and let’s do all the things above to make our apps performant in low-memory devices. best possible checklist here .
the cliched term is true and lack of common sense on our part can have expensive performance repercussions. or may be, this is just me . late night coding sessions are great for ego & getting stuff done; but let’s sleep on it & review our work the next day for sanity checks. i have done stupid things like setting a background image on a panorama/grid & then the same one on every panel; result – double the brush memory gets loaded & counted against the app footprint. a responsive ui wins the battle any day over a complex layout. no unnecessary namespaces, proper use of threading & resources and general common sense = wonderfully performant windows phone apps. and a proud you, right?
would really appreciate any feedback. tell me what i missed. what techniques do you use?
Published at DZone with permission of Samidip Basu, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.