Making mobile flex apps blazing fast

40
MAKING MOBILE FLEX APPS BLAZING FAST Michał Wróblewski

description

This is my presentation i did at try{harder} conference ( http://tryharder.org.uk/ ) about mobile flex apps and how to make them fast.

Transcript of Making mobile flex apps blazing fast

Page 1: Making mobile flex apps blazing fast

MAKING MOBILE FLEX APPS

BLAZING FAST Michał Wróblewski

Page 2: Making mobile flex apps blazing fast

ABOUT

@wrobel221

Live in Poznań, Poland

We make games in

BlackMoon Design

I come from Świebodzin

Page 3: Making mobile flex apps blazing fast

QUICK OUTLINE

Quick intro to Flex Mobile.

A hard way from 5 FPS to 30+ FPS?

Tricks’n’Tips

The Robotlegs Way

Q&A

Page 4: Making mobile flex apps blazing fast

SOMETHING ABOUT YOU

How many of you got your hands dirty with mobile

(especially Flex Mobile) development?

Page 5: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATORAPPLICATION

You can choose one of these:

ViewNavigatorApplication

TabbedViewNavigatorApplication

SplitViewNavigatorApplication

(coming with Flex 4.6)

Page 6: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATORAPPLICATION

Contains an instance(s) of

ViewNavigator(s).

You setup some global properties of

your app e.g, ActionBar content

Page 7: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATORAPPLICATION

Page 8: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATORAPPLICATION

Page 9: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATOR

Manages moving between views.

Has a stack of view data objects

By default only one view exists, others are

destroyed after remove (only data persists)

Setup of default transitions

Access to current view

Page 10: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATOR

Navigation methods:

replaceView,

pushView,

popView,

popToFirstView,

popAll

Page 11: Making mobile flex apps blazing fast

QUICK INTRO - VIEWNAVIGATOR

Skin states:

portrait,

landscape,

portraitAndOverlay,

landscapeAndOverlay

Page 12: Making mobile flex apps blazing fast

QUICK INTRO - VIEW

Visual container for a view of your mobile app.

You should only add mobile-optimised Flex

components here

Accepts data passed in pushView

Returns data by overriding createReturnObject()

Has destructionPolicy (default – auto) to control

whether the view should be destroyed on pop or

just cached.

Setup menu by placing ViewMenuItem in a

<s:viewMenuItems> tag.

Page 13: Making mobile flex apps blazing fast

QUICK INTRO – COMMONS

Label

Icon

actionContent

navigationContent

Page 14: Making mobile flex apps blazing fast

OPTIMIZATION

Page 15: Making mobile flex apps blazing fast

OPTIMIZATION - BITMAPS

Page 16: Making mobile flex apps blazing fast

OPTIMIZATION - BITMAPS

BitmapImage:

Extends GraphicElement

Remote loading

Scaling

Caching

Page 17: Making mobile flex apps blazing fast

OPTIMIZATION - BITMAPS

Image (spark)

Extends SkinnableComponent

Has BitmapImage

Supports progress

Broken image icon

Custom skinning

Page 18: Making mobile flex apps blazing fast

OPTIMIZATION - BITMAPS

BitmapImage 3x faster than spark Image

Try to avoid compressed image formats like JPG

Do caching (on by default) and queuing (off by

default) by using ContentCache. Assign it to

contentLoader property of BitmapImage and Image

Page 19: Making mobile flex apps blazing fast

OPTIMIZATION - TEXT

RichEditableText

RichText

Label

StyleableTextField (new in Flex 4.5)

StageText (coming in Flex 4.6)

Page 20: Making mobile flex apps blazing fast

OPTIMIZATION - TEXT

Only StyleableTextField extends flash.text.TextField

Can’t use StyleableTextField directly in MXML, so

you’re quite pushed to use it in AS3.

Page 21: Making mobile flex apps blazing fast

OPTIMIZATION – LISTS AND ITEMRENDERERS

All mentioned before apply

uber-optimized LabelItemRenderer and

IconItemRenderer

Page 22: Making mobile flex apps blazing fast

OPTIMIZATION – LISTS AND ITEMRENDERERS

Mobile item renderers – if possible use bundler uber-optimized LabelItemRenderer and IconItemRenderer, they were shown in all Flex Mobile demos.

Avoid complex binding expressions.

Turn off autoDrawBackground if not needed.

Use cacheAsBitmap, but be careful.

Use opaqueBackground

itemRendererFunction prevents pooling and recycling.

Favor FXG over spark graphic elements (if possible)

Page 23: Making mobile flex apps blazing fast

OPTIMIZATION - SKINS

Extend MobileSkin instead of SparkSkin

AS3 version will perform better than MXML

Use FXG for static vector graphics, use where

possible

Use GraphicElement as lightweight graphic

primitives. E.g. Backgrounds, borders etc.

Page 24: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Adding platform specific UI patterns CSS media rules

Separate projects with common code base

Ready multiplatform mobile themes

Page 25: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Handling multi DPI devices with

MultiDPIBitmapSource

Page 26: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Be sure not to put references to view

instances anywhere.

Page 27: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Don’t interfere expensive process of parsing

data into view when doing a transition.

Use BusyIndicator before or after transition.

Page 28: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Don’t cheat by testing your app on a high-end

smartphone

Page 29: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Please don’t use filters.

Page 30: Making mobile flex apps blazing fast

TRICKS’N’TIPS

Have memory usage and limitations in mind

Page 31: Making mobile flex apps blazing fast

TRICKS’N’TIPS

On every level make your display list as flat

as possible.

Use Shaun’s script to show more info about

the display list tree

Page 32: Making mobile flex apps blazing fast

TRICKS’N’TIPS

At the end:

[profile, test, optimize].loop()

Page 33: Making mobile flex apps blazing fast

THE ROBOTLEGS WAY

Page 34: Making mobile flex apps blazing fast

THE ROBOTLEGS WAY

“I and my team have been using Robotlegs to build

several apps for many months, and I've never had

any issues caused by Robotlegs”

Paul Robertson

Page 35: Making mobile flex apps blazing fast

THE ROBOTLEGS WAY

Views are being destroyed when you push a new

view.

The same will happen with Mediators

Page 36: Making mobile flex apps blazing fast

THE ROBOTLEGS WAY

You’ll need an instance of ViewNavigator in your

navigator manager.

Page 37: Making mobile flex apps blazing fast

THE ROBOTLEGS WAY

Don’t hesitate to use viewManager in your View.

Dispatch a command only if you need some data

from the rest of the application.

Page 38: Making mobile flex apps blazing fast

THE ROBOTLEGS WAY

Page 39: Making mobile flex apps blazing fast

A QUESTION TO YOU

How do you approach multiscreen

development?

Page 40: Making mobile flex apps blazing fast

THANKS!

Any questions?