SlideShare a Scribd company logo
1 of 35
SOCIAL SPEED Improving Flash Performance AmittMahajan, Zynga
My Background Worked on Gears of War & Unreal Engine 3 at Epic Co-founder / CTO, MyMiniLife Flash Virtual World, Acquired by Zynga in 2009 Director of Engineering, Zynga Co-creator & Lead Developer, FarmVille/Treasure Isle Built the first prototype of CityVille Created ZEngine and ExampleVille, Zynga’s common game engine and game framework
High-Level Takeaways Load time impacts new installs Runtime performance impacts retention Gather real data to know where to spend your time Try to optimize as low-level as possible and build checks into your build process Performance deteriorates over-time and needs to be continually re-examined
Loading Extended load-time causes people to navigate away from your game We define load-time as the period the player has to wait for the app to become interactive
Common Reasons for Loading Delays Downloading your game SWF Waiting for Facebook API to respond Round-trip for player data from game servers Asset size and number of assets Computation (depth-sorting, parsing XML, etc.)
Measuring Load-Times FireBug can be used for asset load measurement The Flash Builder profiler can give insight into where load-time computation is occurring Link-exports can determine why your SWF is a certain size
Using Link-Export Flash’s compiler provides a link-export option to export size breakdown of a SWF mxmlc -link-report=C:ourLinkReport.xmlYourApp.as
Using Link-Export We use a tool* to visualize the link-report and identify assets to remove from the SWF * http://www.kahunaburger.com/2008/03/08/air-link-report-visualizer/
Reducing Waits on Social Networks Social network data retrievals significantly impact load-times Ideally, don’t require social network data at all to load the game A compromise is to pre-fetch social network data server-side and then embed it into Javascript
Normal Facebook Data Flow GAME SERVER (PHP) CLIENT (FLASH) FACEBOOK Your CanvasCallback apps.facebook.com/yourapp Initial Page Load users.getLoggedInUser() Render Flash HTML friends.get() friends.get()
Optimized Facebook Data Flow GAME SERVER (PHP) CLIENT (FLASH) FACEBOOK Your CanvasCallback apps.facebook.com/yourapp Initial Page Load Fetch all Facebook Data users.getLoggedInUser() friends.get() Render Flash HTML &  Data JSON Retrieve User/Friend Data From JS JSON object
Optimizing Initial Asset Load Set the bar high for what needs to be loaded at all Both asset size and number of assets matter Version assets and use correct HTTP headers to ensure that assets will be cached by the browser Expires: Fri, 24 Feb 2012 03:06:45 GMT Cache-Control: max-age=2592000
Optimizing Asset Size Use low-res assets first and stream in high-res assets later Pack PNG assets into SWF files for additional compression PNG: 20kb SWF (50%): 4.2kb SWF (30%): 2.5kb
Asset Bundling Bundle similar assets together in a SWF to avoid a DNS look-up and HTTP connection round-trip for each asset road.swf road1.png road2.png road1 road2 Add assets to a SWF library and compile road4.png road3.png road4 road3
Multiple Asset Domains  HTTP spec has a request limit per domain, can get around this by having DNS aliases assets0.farmville.com/pig.png LoadingManager.load() ++loadCount%4 assets1.farmville.com/pig.png Load pig.png Flash Client assets2.farmville.com/pig.png assets3.farmville.com/pig.png
Pre-Computing Static Game Data XML & JSON can be expensive to parse and download Can pre-compile this data into Flash SWF files for download and processing savings Raw Static Data (XML, JSON, Text, etc.) Auto-generated .as file that embeds data in a Dictionary Compressed  .SWF file Loaded Data Generate  AS3 Code Download& Load Class MXMLC
Runtime Performance Runtime performance is defined by perceived responsiveness of the application Sluggish performance hampers users enjoyment of the game Runtime performance issues also reduce interactivity
How Performance Affects Virality # Of Social Actions 0-4 5-8 9-12 13-16 17-20 21-24 25+ FPS
Common Causes of Slow Performance Poorly authored assets Vector instead of Bitmap, Excessive Animation Unoptimized game loops Iterating over all game objects, excessive object allocation/deallocation Flash VM CPU hogging Expensive graphics filters, continually updating display list
Measuring Runtime Performance FPS is a good starting metric to make visible on dev builds The Flash Builder profiler is solid and the normal profile/fix issues cycle works great for AS3 It is harder to see where draw-time is going, redraw regions help
Redraw Regions Redraw regions show you where your render time is going and can help identify problems
Authoring Assets Vector assets render slower than bitmaps Bitmap assets have larger file sizes than vector A hybrid-approach can give the best of both worlds
Farmville Pig This asset killed our frame-rate due to unnecessary vectors *Vector images courtesy of Justin Church (byxb.com)
Vector / Bitmap Hybrid All assets are downloaded by the Flash client as vector At load-time, generate rasterized bitmap sprite sheets at the lowest possible resolution that avoids scaling If necessary, re-generate bitmaps at higher resolutions
Bitmap Sprite Sheets Alternative to vector-based animation Uses fast pixel-based operations CityVille_ConstructionWorker.png
No-Draw Sprite Sheets First, we pre-split the Bitmap Original Bitmap BitmapData.copyPixels() One Bitmap Data Object per Frame
No-Draw Sprite Sheets Shared BitmapData Objects Instance of an Animated Object Bitmap  Object .bitmapData
Flash CPU Usage  Flash can consumes CPU and slow down browser performance High CPU usage causes slow responses from social networks
Optimizing the Game Loop Have a single ENTER_FRAME event that drives game updates Split the updating of objects across frames Controlling the game loop also lets you control simulation speeds by adjusting time delta
Game Loop Flow ENTER_FRAME callback Game.updateWorld() Choose bucket in  round-robin fashion Bucket 0 Bucket 1 Bucket 2 Bucket 3 Objects[0] Objects[4] Objects[8] Objects[3] Objects[7] Objects[11] Objects[1] Objects[4] Objects[9] Objects[2] Objects[6] Objects[10] Call .update(timeDelta) on each object in bucket
Screen Freezing Swap Flash with Static Bitmap to reduce CPU Freeze background processing & replace with Bitmap FB.ui() Un-freeze background processing & show Flash again
Optimization Best Practices Optimization for social games is on-going, even post-launch Build-in detection of bad assets and code into your build process Have your client report back performance metrics, and actually use the data to fix issues Continually monitor your load-time and initial download size; They tend to increase over time
|  Thank you!  Questions? Email: amahajan@zynga.com Twitter: @amittm Blog: www.amitt.com

More Related Content

What's hot

GENERATE PDF OF A WEB PAGE
GENERATE PDF OF A WEB PAGEGENERATE PDF OF A WEB PAGE
GENERATE PDF OF A WEB PAGEBikash Sundaray
 
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014ICS User Group
 
Logging Wars: A Cross-Product Tech Clash Between Experts
Logging Wars: A Cross-Product Tech Clash Between Experts Logging Wars: A Cross-Product Tech Clash Between Experts
Logging Wars: A Cross-Product Tech Clash Between Experts Benedek Menesi
 
Open Mic on Managed Mail Replica
Open Mic on Managed Mail ReplicaOpen Mic on Managed Mail Replica
Open Mic on Managed Mail Replicajayeshpar2006
 
Speed up your site! #wcmtl2015 by Meagan Hanes
Speed up your site! #wcmtl2015 by Meagan HanesSpeed up your site! #wcmtl2015 by Meagan Hanes
Speed up your site! #wcmtl2015 by Meagan HanesMeagan Hanes
 
IBM Verse On-premises
IBM Verse On-premisesIBM Verse On-premises
IBM Verse On-premisesjayeshpar2006
 
RIA Development via Adobe Flex + JRuby on Rails
RIA Development via Adobe Flex + JRuby on RailsRIA Development via Adobe Flex + JRuby on Rails
RIA Development via Adobe Flex + JRuby on Railskamal.fariz
 
From frustration to fascination: dissecting Replication
From frustration to fascination: dissecting ReplicationFrom frustration to fascination: dissecting Replication
From frustration to fascination: dissecting ReplicationBenedek Menesi
 
Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...
Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...
Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...Salesforce Admins
 
Buzzword, How'd They Build That?
Buzzword, How'd They Build That?Buzzword, How'd They Build That?
Buzzword, How'd They Build That?dcoletta
 

What's hot (12)

GENERATE PDF OF A WEB PAGE
GENERATE PDF OF A WEB PAGEGENERATE PDF OF A WEB PAGE
GENERATE PDF OF A WEB PAGE
 
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
 
Logging Wars: A Cross-Product Tech Clash Between Experts
Logging Wars: A Cross-Product Tech Clash Between Experts Logging Wars: A Cross-Product Tech Clash Between Experts
Logging Wars: A Cross-Product Tech Clash Between Experts
 
Open Mic on Managed Mail Replica
Open Mic on Managed Mail ReplicaOpen Mic on Managed Mail Replica
Open Mic on Managed Mail Replica
 
Speed up your site! #wcmtl2015 by Meagan Hanes
Speed up your site! #wcmtl2015 by Meagan HanesSpeed up your site! #wcmtl2015 by Meagan Hanes
Speed up your site! #wcmtl2015 by Meagan Hanes
 
IBM Verse On-premises
IBM Verse On-premisesIBM Verse On-premises
IBM Verse On-premises
 
RIA Development via Adobe Flex + JRuby on Rails
RIA Development via Adobe Flex + JRuby on RailsRIA Development via Adobe Flex + JRuby on Rails
RIA Development via Adobe Flex + JRuby on Rails
 
PhoneGap/Cordova
PhoneGap/CordovaPhoneGap/Cordova
PhoneGap/Cordova
 
Scaling small apps
Scaling small appsScaling small apps
Scaling small apps
 
From frustration to fascination: dissecting Replication
From frustration to fascination: dissecting ReplicationFrom frustration to fascination: dissecting Replication
From frustration to fascination: dissecting Replication
 
Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...
Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...
Lightning Components for Admins by Farhan Carter, LeeAnne Templeman, & Michae...
 
Buzzword, How'd They Build That?
Buzzword, How'd They Build That?Buzzword, How'd They Build That?
Buzzword, How'd They Build That?
 

Similar to Social Speed - Improving Flash Performance for Social Games (GDC 2011)

Designing the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineDesigning the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineChris Bunch
 
Facebook flash api and social game development
Facebook flash api and social game developmentFacebook flash api and social game development
Facebook flash api and social game developmentYenwen Feng
 
Windows Phone 7 and Silverlight
Windows Phone 7 and SilverlightWindows Phone 7 and Silverlight
Windows Phone 7 and SilverlightGlen Gordon
 
The tech. behind RoboBlastPlanet
The tech. behind RoboBlastPlanetThe tech. behind RoboBlastPlanet
The tech. behind RoboBlastPlanetJavier Abud
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsLuca Galli
 
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...Amazon Web Services
 
Mobile Cloud Computing for Games - Gamelet
Mobile Cloud Computing for Games - Gamelet Mobile Cloud Computing for Games - Gamelet
Mobile Cloud Computing for Games - Gamelet Anand Bhojan
 
PHP Continuous Data Processing
PHP Continuous Data ProcessingPHP Continuous Data Processing
PHP Continuous Data ProcessingMichael Peacock
 
20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's new20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's newMeng-Ru (Raymond) Tsai
 
Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf euXie ChengChao
 
112 portfpres.pdf
112 portfpres.pdf112 portfpres.pdf
112 portfpres.pdfsash236
 
Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...
Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...
Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...DevGAMM Conference
 
20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's new20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's newMeng-Ru (Raymond) Tsai
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.jsXie ChengChao
 
Introduction to html5 game programming with ImpactJs
Introduction to html5 game programming with ImpactJsIntroduction to html5 game programming with ImpactJs
Introduction to html5 game programming with ImpactJsLuca Galli
 
The post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart NeedhamThe post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart NeedhamStewart Needham
 
Ajax to the Moon
Ajax to the MoonAjax to the Moon
Ajax to the Moondavejohnson
 

Similar to Social Speed - Improving Flash Performance for Social Games (GDC 2011) (20)

Designing the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineDesigning the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App Engine
 
Facebook flash api and social game development
Facebook flash api and social game developmentFacebook flash api and social game development
Facebook flash api and social game development
 
Windows Phone 7 and Silverlight
Windows Phone 7 and SilverlightWindows Phone 7 and Silverlight
Windows Phone 7 and Silverlight
 
The tech. behind RoboBlastPlanet
The tech. behind RoboBlastPlanetThe tech. behind RoboBlastPlanet
The tech. behind RoboBlastPlanet
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
 
Play framework
Play frameworkPlay framework
Play framework
 
Mobile Cloud Computing for Games - Gamelet
Mobile Cloud Computing for Games - Gamelet Mobile Cloud Computing for Games - Gamelet
Mobile Cloud Computing for Games - Gamelet
 
PHP Continuous Data Processing
PHP Continuous Data ProcessingPHP Continuous Data Processing
PHP Continuous Data Processing
 
20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's new20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's new
 
Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf eu
 
112 portfpres.pdf
112 portfpres.pdf112 portfpres.pdf
112 portfpres.pdf
 
Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...
Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...
Modern Data Stack for Game Analytics / Dmitry Anoshin (Microsoft Gaming, The ...
 
20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's new20130923 tech days windows 8.1 what's new
20130923 tech days windows 8.1 what's new
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
 
Drupal & Flash
Drupal & FlashDrupal & Flash
Drupal & Flash
 
Introduction to html5 game programming with ImpactJs
Introduction to html5 game programming with ImpactJsIntroduction to html5 game programming with ImpactJs
Introduction to html5 game programming with ImpactJs
 
The post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart NeedhamThe post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart Needham
 
Ajax to the Moon
Ajax to the MoonAjax to the Moon
Ajax to the Moon
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Social Speed - Improving Flash Performance for Social Games (GDC 2011)

  • 1. SOCIAL SPEED Improving Flash Performance AmittMahajan, Zynga
  • 2. My Background Worked on Gears of War & Unreal Engine 3 at Epic Co-founder / CTO, MyMiniLife Flash Virtual World, Acquired by Zynga in 2009 Director of Engineering, Zynga Co-creator & Lead Developer, FarmVille/Treasure Isle Built the first prototype of CityVille Created ZEngine and ExampleVille, Zynga’s common game engine and game framework
  • 3. High-Level Takeaways Load time impacts new installs Runtime performance impacts retention Gather real data to know where to spend your time Try to optimize as low-level as possible and build checks into your build process Performance deteriorates over-time and needs to be continually re-examined
  • 4. Loading Extended load-time causes people to navigate away from your game We define load-time as the period the player has to wait for the app to become interactive
  • 5. Common Reasons for Loading Delays Downloading your game SWF Waiting for Facebook API to respond Round-trip for player data from game servers Asset size and number of assets Computation (depth-sorting, parsing XML, etc.)
  • 6. Measuring Load-Times FireBug can be used for asset load measurement The Flash Builder profiler can give insight into where load-time computation is occurring Link-exports can determine why your SWF is a certain size
  • 7. Using Link-Export Flash’s compiler provides a link-export option to export size breakdown of a SWF mxmlc -link-report=C:ourLinkReport.xmlYourApp.as
  • 8. Using Link-Export We use a tool* to visualize the link-report and identify assets to remove from the SWF * http://www.kahunaburger.com/2008/03/08/air-link-report-visualizer/
  • 9. Reducing Waits on Social Networks Social network data retrievals significantly impact load-times Ideally, don’t require social network data at all to load the game A compromise is to pre-fetch social network data server-side and then embed it into Javascript
  • 10. Normal Facebook Data Flow GAME SERVER (PHP) CLIENT (FLASH) FACEBOOK Your CanvasCallback apps.facebook.com/yourapp Initial Page Load users.getLoggedInUser() Render Flash HTML friends.get() friends.get()
  • 11. Optimized Facebook Data Flow GAME SERVER (PHP) CLIENT (FLASH) FACEBOOK Your CanvasCallback apps.facebook.com/yourapp Initial Page Load Fetch all Facebook Data users.getLoggedInUser() friends.get() Render Flash HTML & Data JSON Retrieve User/Friend Data From JS JSON object
  • 12. Optimizing Initial Asset Load Set the bar high for what needs to be loaded at all Both asset size and number of assets matter Version assets and use correct HTTP headers to ensure that assets will be cached by the browser Expires: Fri, 24 Feb 2012 03:06:45 GMT Cache-Control: max-age=2592000
  • 13. Optimizing Asset Size Use low-res assets first and stream in high-res assets later Pack PNG assets into SWF files for additional compression PNG: 20kb SWF (50%): 4.2kb SWF (30%): 2.5kb
  • 14. Asset Bundling Bundle similar assets together in a SWF to avoid a DNS look-up and HTTP connection round-trip for each asset road.swf road1.png road2.png road1 road2 Add assets to a SWF library and compile road4.png road3.png road4 road3
  • 15. Multiple Asset Domains HTTP spec has a request limit per domain, can get around this by having DNS aliases assets0.farmville.com/pig.png LoadingManager.load() ++loadCount%4 assets1.farmville.com/pig.png Load pig.png Flash Client assets2.farmville.com/pig.png assets3.farmville.com/pig.png
  • 16. Pre-Computing Static Game Data XML & JSON can be expensive to parse and download Can pre-compile this data into Flash SWF files for download and processing savings Raw Static Data (XML, JSON, Text, etc.) Auto-generated .as file that embeds data in a Dictionary Compressed .SWF file Loaded Data Generate AS3 Code Download& Load Class MXMLC
  • 17. Runtime Performance Runtime performance is defined by perceived responsiveness of the application Sluggish performance hampers users enjoyment of the game Runtime performance issues also reduce interactivity
  • 18. How Performance Affects Virality # Of Social Actions 0-4 5-8 9-12 13-16 17-20 21-24 25+ FPS
  • 19. Common Causes of Slow Performance Poorly authored assets Vector instead of Bitmap, Excessive Animation Unoptimized game loops Iterating over all game objects, excessive object allocation/deallocation Flash VM CPU hogging Expensive graphics filters, continually updating display list
  • 20. Measuring Runtime Performance FPS is a good starting metric to make visible on dev builds The Flash Builder profiler is solid and the normal profile/fix issues cycle works great for AS3 It is harder to see where draw-time is going, redraw regions help
  • 21. Redraw Regions Redraw regions show you where your render time is going and can help identify problems
  • 22. Authoring Assets Vector assets render slower than bitmaps Bitmap assets have larger file sizes than vector A hybrid-approach can give the best of both worlds
  • 23. Farmville Pig This asset killed our frame-rate due to unnecessary vectors *Vector images courtesy of Justin Church (byxb.com)
  • 24.
  • 25.
  • 26. Vector / Bitmap Hybrid All assets are downloaded by the Flash client as vector At load-time, generate rasterized bitmap sprite sheets at the lowest possible resolution that avoids scaling If necessary, re-generate bitmaps at higher resolutions
  • 27. Bitmap Sprite Sheets Alternative to vector-based animation Uses fast pixel-based operations CityVille_ConstructionWorker.png
  • 28. No-Draw Sprite Sheets First, we pre-split the Bitmap Original Bitmap BitmapData.copyPixels() One Bitmap Data Object per Frame
  • 29. No-Draw Sprite Sheets Shared BitmapData Objects Instance of an Animated Object Bitmap Object .bitmapData
  • 30. Flash CPU Usage Flash can consumes CPU and slow down browser performance High CPU usage causes slow responses from social networks
  • 31. Optimizing the Game Loop Have a single ENTER_FRAME event that drives game updates Split the updating of objects across frames Controlling the game loop also lets you control simulation speeds by adjusting time delta
  • 32. Game Loop Flow ENTER_FRAME callback Game.updateWorld() Choose bucket in round-robin fashion Bucket 0 Bucket 1 Bucket 2 Bucket 3 Objects[0] Objects[4] Objects[8] Objects[3] Objects[7] Objects[11] Objects[1] Objects[4] Objects[9] Objects[2] Objects[6] Objects[10] Call .update(timeDelta) on each object in bucket
  • 33. Screen Freezing Swap Flash with Static Bitmap to reduce CPU Freeze background processing & replace with Bitmap FB.ui() Un-freeze background processing & show Flash again
  • 34. Optimization Best Practices Optimization for social games is on-going, even post-launch Build-in detection of bad assets and code into your build process Have your client report back performance metrics, and actually use the data to fix issues Continually monitor your load-time and initial download size; They tend to increase over time
  • 35. | Thank you! Questions? Email: amahajan@zynga.com Twitter: @amittm Blog: www.amitt.com