Session 6 – Flash Player Internals

Flash Player is the environment where all of our Flex and Flash products run in, and it also heavily influences the way Adobe AIR functions as well.

Hopefully in this session we’ll see some fundamental functionality of how Flash Player works, and maybe some tricks to alleviate some of the headaches we see as Flash/Flex developers.

Building Flash Players

One source code base builds all the targets, most of which is the “core” and is shared maongst all targets. There’s also some other code that is “platform” specific, such as “mobile platforms,” “netscape platform,” etc, etc.

This allows for Flash to be consistent, cross platform, and optimized. However, there are some differences:

  • Memory & CPUs
  • Screen sizes
  • Mouse, keypad, touch

Infrastructure

There ARE threads in the Flash Player, but conceptually it’s single threaded.
Excecution Model:

  • Browser
  • SWF Actions
  • ActionScript
  • Rendering

While the Execution Model is fully featured, they can not be run at the same time. Renders are queued, with the exception of BitmapData.draw().

Timing Priorities

  • Streaming sound
  • Video
  • ActionScript + Rendering – Clocked back on systems that can’t handle it (mobile)

Player Version vs SWF Version – the version is virtual, even though you run FP10, you might be running a v6 SWF, and thus in all things considered your FP is v6.

New in 10.1

Flash Player handles OOM and shuts down gracefully.
Mobile: Instance management.

ActionScript

AS2 runs on VM-1, which is interpreted.
AS3 runs on AVM-2 “Tamarin”. JIT converts AS3 byte code to executable code. Nanojit is the JIT engine, which has community support and supports multiple processors.
In FP 10.1 we see an improved internal string class, lower memory footprint for the VM, and some GC tuning.

Garbage Collector

  • Overview: primitives, references, and objects
  • GC is NOT memory management
  • Memory management is tricky: IDisposed used by NYT Viewer, disposes of all memory items upon Disposal (manually called obviously)
  • Prime numbers are a useful trick – check for multiples of that prime number to find a link.

 

Rendering

Video is now being decoded on the GPU!!!! YAY!!! Works only on h264 encoding, with driver testing and certification. Should be pretty common, but check your user-base before assuming it’ll work. This improves power usage and framerate, and supported in all wmodes.

New in 10.1

JPEG decompresses on demand!
Survace instancing, meaning no per-bitmap mem cost for read-only bitmaps.
Bitmap gleaning will release memory as bitmaps are done being used.
Direct mip-mapping, which is extra important for mobile.
GPU Vector Acceleration is coming to mobile only (at first), which fully replaces the software renderer with a GPU based renderer.

Performance Bottlenecks

ActionScript – Use AS3, and beware of intervals and high frame rates.
DisplayList (mobile) – Keep it small, and don’t use too many Sprites.
Video – Size, format, and framerate appropriate for target.
GC – Umm.. Tricky stuff. He didn’t go into it and isn’t taking questions.

Advertisements

About killerspaz

I'm a developer that loves to tinker with cutting edge technology. I have recently been playing with the Flash Platform (AS3/Flex), Android (custom roms, replacement apps, scripting), and looking at opportunities in the mobile markets.

Posted on 10.06.2009, in Adobe MAX and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: