Top Banner
Saving a Century a Day: Cut image loading time in half Tyrone Nicholas Software Engineer 10 October 2014
27

How Facebook cut image load times in half

Jul 01, 2015

Download

Internet

Tyrone Nicholas
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: How Facebook cut image load times in half

Saving a Century a Day:Cut image loading time in half

Tyrone Nicholas

Software Engineer

10 October 2014

Page 2: How Facebook cut image load times in half

Demo

Page 3: How Facebook cut image load times in half

The Image Pipeline

JPG

BMP

BMP JPG

JPG

JPG

UI thread Non-UI threads

Page 4: How Facebook cut image load times in half

The bane of our existence

Page 5: How Facebook cut image load times in half

Android memory heapsDalvik Native

Page 6: How Facebook cut image load times in half

Native memory

Page 7: How Facebook cut image load times in half

Using native memory“Naïve native”

Page 8: How Facebook cut image load times in half

Native pools and streams

Page 9: How Facebook cut image load times in half

Native pools and streams

OutputStream

InputStream

Image Operation

Native Chunk

Native Chunk

Native ChunkNative

Chunk

Pool

Page 10: How Facebook cut image load times in half

Pinned purgeables

Page 11: How Facebook cut image load times in half

PurgeablesHowto

Page 12: How Facebook cut image load times in half

How purgeables work

Need memory?

Look for unpinned memory

Free it

Ashmem

• allocate

• pin

• unpin

Page 13: How Facebook cut image load times in half

How purgeables work

Allocate Draw Pin Decode

Stop drawing

Unpin

Draw cycle

Page 14: How Facebook cut image load times in half

Er, wait a minute…

Page 15: How Facebook cut image load times in half

How to do it (1)

Page 16: How Facebook cut image load times in half

How to do it (2)

Page 17: How Facebook cut image load times in half

Benefits

Page 18: How Facebook cut image load times in half

Risks

Page 19: How Facebook cut image load times in half

Reference counting in Java

Page 20: How Facebook cut image load times in half

SharedReference

Page 21: How Facebook cut image load times in half

CloseableReference

Page 22: How Facebook cut image load times in half

Using references

Page 23: How Facebook cut image load times in half

When?

Page 24: How Facebook cut image load times in half

When are you done with a bitmap?

Page 25: How Facebook cut image load times in half

Safe closing

Page 26: How Facebook cut image load times in half

Put byte buffers in native memory

Use purgeable bitmaps and pin them

Free your objects at the right time

Page 27: How Facebook cut image load times in half

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

tnicholas @ fb.com

Twitter: @tyronen

We’re hiring!