saving a century a day: how the fresco library works

25
Fresco saving a century a day Tyrone Nicholas Software Engineer Aug. 27, 2015

Upload: tyrone-nicholas

Post on 29-Jan-2018

856 views

Category:

Technology


1 download

TRANSCRIPT

Frescosaving a century a day

Tyrone Nicholas

Software Engineer

Aug. 27, 2015

The Image Pipeline

JPG

BMP

BMP JPG

JPG

JPG

UI thread Non-UI threads

Demo

Source: run_comparison script, Moto G, KitKat. Results will vary with different devices, images, and network conditions.

Keeping ahead of the UI• UI draws 60 frames per second

• = 16 ms / frame

• On all devices

Images are big, devices are small

Samsung Galaxy Tab 2

• 800 x 1280 pixels

• 4 bytes per pixel

• = 3.9 MB

• 1 GB RAM

• but only 48 MB heap!

Android heaps

Java

▪ JDK

▪ Limited

▪ Slow

▪ Safe

Ashmem

▪ Certain system

calls

▪ Unlimited, fast

▪ Safe (sort of)

▪ Use for BMP

Native

▪ NDK

▪ Unlimited

▪ Fast

▪ Unsafe

▪ Use for JPEG

Ashmem

Need memory?

Look for unpinned memory

Free and reallocate

▪ allocate

▪ free (indirect)

▪ pin

▪ unpin

Purgeable bitmaps

Draw Pin Decode

Stop drawing

Unpin

Er, wait a minute…

inBitmap?

Fresco’s solution

Benefit

You always have to…

but when?

DraweeView – a better ImageView

• Release bitmap memory

• Cancel network / disk requests

DraweeView

Show placeholder

image

Show actual image

Fade-inanimation

Scale

Round

Scale

Round

Show failureimage

Round

Scale

Load from image

pipeline

Worked?

Last scan?

No

Yes

No

Updateprogres

s bar

Tap to

Retry

Progressive JPEG

Using Fresco

Focus Point Cropping

Animations

Postprocessing

(c) 2009 Facebook, Inc. or its licensors. "Facebook" is a registered trademark of Facebook, Inc.. All rights reserved. 1.0

http://frescolib.org

tnicholas @ fb.com

Twitter: @tyronen

We’re hiring!