SlideShare a Scribd company logo
1 of 37
Download to read offline
How Javascript V8 Works
Who am I?
• Vaugham Hong
• Electronic Arts - rendering / systems
• BigPark / Microsoft - gameplay / scripting
• ConquerMobile, AlkanAir, Colligo , nGrain…etc. - full
stack
• uForis VR - full stack
! web_dev
VR x V8
• Explored 360 panoramas /
videos and 3D spaces
• Early 2014 - Custom
markup to create static
connected 3D spaces
• eg. Model, Portal, Video,
Image elements
• Early 2015 - V8 JS
integration
• Dynamic spaces
VR x V8
• Shader Toys
• Youtube
VR x V8
• Chromium
• Emulator
How Javascript V8 Works
What is V8?
• V8 is Google’s high performance Javascript engine
• Desktop Chrome September, 2008 (55% MS 2016)
• Android Chrome September, 2012 (80% MS 2016)
• Node.JS
Embedding V8
App
Load / Run Script
JS to Native
Function Call
Initialize
Native to JS
Function Call
Destroy
V8
Embedding V8
INCLUDED NOT INCLUDED
Array
Math
Date
Number
Object
…
DOM
WebGL
require
Today
• JIT
• Full compiler
• Optimized compiler
• Garbage collection
• New space - scavenge
• Old space - mark-sweep / mark-compact
V8 JIT Overview
• Compile one function at a time - as they are
encountered
• Constant startup latency
• Never compile code that is unreachable
• Two compilers
• Full compiler
• Optimization compiler (CrankShaft)
Full Compiler
• Goal - Spit out machine code as quickly as possible
• Don’t worry too much about optimizations
• No intermediate language / No byte code
• Javascript => Machine Code
• Profile for hot functions
Javascript
Machine
Code
Parse JS Code-GenAST
Hot-ness
• Counter based profiling
• Decrement counter exiting functions
• Flag for optimization when reaching 0
• Deterministic
Optimized Compiler
• Goal - spit out optimized machine code
• Hydrogen IL - includes type info, scope info for
optimizations (Inlining, dead code elimination, range
analysis, static type inference, …etc.)
• Lithium IL - optimized ready for machine code generation
Javascript
Machine
Code
Parse JS
Scope
AnalysisAST
Graph
Gen
L. ILOptimizationH. IL
Code
Gen
De-optimization
• V8 could decide to go back to un-optimized code
• Adding / deleting properties may void optimization contract
• Too many de-optimizations and V8 may stop optimizing entirely
• Constructs like try / catch will make code ineligible for optimizations
• https://github.com/vhf/v8-bailout-reasons
• Un-optimized code will run GC a little hotter
Un-Optimized Optimized
V8 GC Overview
• Automatic lifetime management
• How do you allocate objects?
• How / when do you deallocate objects?
• Generational GC
• Young / old objects
GC “Spaces”
NEW
SPACE
OLD
SPACE
OBJECT
TYPE Young Old
OBJECT
SIZE
Small Small - Large
COLLECTION
FREQUENCY
High Low
COLLECTION
TIME
Short Long
HEAP
SIZE
1-8 MB Sky’s the limit
Each space contains a set of 1MB pages
New Space
• Stack based allocator
• Collect when full
• Uses Cheney’s “Stop-and-
copy” algorithm to reclaim
memory
NEW
SPACE
OBJECT
TYPE
Young
OBJECT
SIZE
Small
COLLECTION
FREQ High
COLLECTION
TIME Short
SIZE 1-8 MB
New Space
Scavenge
Empty
To Space
From Space
New Space
Scavenge
Allocate A, B, C
To Space
From Space
A CB
New Space
Scavenge
Not enough space allocating D
Pause GC and scavenge
To Space
From Space
A CB D
New Space
Scavenge
Swap To and From Space
To Space
From Space
A CB
New Space
Scavenge
To Space
From Space
A C
Retain Live Objects
New Space
Scavenge
Allocate D
To Space
From Space
A C D
Pointer Discovery
• Pointers
• Data (eg. strings, numbers)
0x2144AC80
0x3426D100
0x057SCC10
0x31054AD0
0x00A2FF11
0x122AD100
0x00A2FFA1
0x00A2FA11
Pointer Discovery
Tagged Pointers
• 32-bit V8 allocations are 4
byte aligned
• Last two bits of an address
are always zero
• Use last two bits to encode
hidden data
• 00 - data
• 01 - pointer
0x04
0x00
0x08
0x0C
0x10
0x1C 11100
10000
01100
01000
00100
00000
Hex Binary
0x2144AC80
0x3426D100
0x057SCC10
0x31054AD0
0x00A2FF11
0x122AD100
0x00A2FFA1
0x00A2FA11
Pointer Discovery
Tagged Pointers
0x31054AD0 0x31054AD0
Data
0x00A2FF11 0x00A2FF10
Pointer
Pointer Discovery
Tagged Pointers
data
pointer
data
pointer
pointer
0x2144AC80
0x3426D100
0x057SCC10
0x31054AD0
0x00A2FF11
0x122AD100
0x00A2FFA1
0x00A2FA11
Old Space
• Free-list based
• Collect on threshold size
• Mark-Sweep to reclaim
memory
• Mark-Compact to reclaim
pages
OLD
SPACE
OBJECT
TYPE
Old
OBJECT
SIZE
Any
COLLECTION
FREQ Low
COLLECTION
TIME Long
SIZE Sky’s the limit
Old Space
Mark Phase
data
pointer
data
pointer
pointer
0
0
0
0
0
0
0
data
pointer
data
pointer
pointer
1
0
0
1
1
1
1
Old Space
Sweep
D
E
F
G
A
B
C
1
0
0
0
1
1
0
F
G
Page Free List
D
E
F
G
A
B
C
1
0
0
0
1
1
0
F
G
Page Free List
C
E
Old Space
Compact
pointer
data
data
data
pointer
data
pointer
pointer
data
data
data
data
Page 1
Page 2
Page 1
Page 2
Reclaim
Wrap Up
• Cooperate with the JIT
• Write scripts that stay optimized
• De-optimization puts pressure on GC
• Pre allocate as much as possible
• Don’t let allocations pile up and force collection
cycles
uForis + V8
• Live editing with Javascript
• Natively backed scene management, particle systems,
physics, rendering, material systems, async I/O, …etc.
• CommonJS compliant => NPM module support
• 1000 FPS!
• Platforms
• Oculus, Vive, Cardboard, GearVR
• Win32, OSX, iOS, Android
Questions?
• LinkedIn - https://ca.linkedin.com/in/vaughamhong
• E-mail - vaugham@uforis.com
• Twitter - vaughamhong
We are hiring!
• Interested in joining the virtual reality industry?
• Want to find ways to help apply virtual reality in
practical business problems?
• Highly organized, efficient, and excited about how
virtual reality software development works?
• We'd love to hear from you!
• http://www.uforis.com/careers

More Related Content

What's hot

What's hot (20)

Universal JavaScript - Frontend United Athens 2017
Universal JavaScript - Frontend United Athens 2017Universal JavaScript - Frontend United Athens 2017
Universal JavaScript - Frontend United Athens 2017
 
Angular 2 observables
Angular 2 observablesAngular 2 observables
Angular 2 observables
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMS
 
State in stateless serverless functions
State in stateless serverless functionsState in stateless serverless functions
State in stateless serverless functions
 
GraphQL, Redux, and React
GraphQL, Redux, and ReactGraphQL, Redux, and React
GraphQL, Redux, and React
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless World
 
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, EverAltitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
 
Altitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshopAltitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshop
 
We broke up with the monolith, and started dating #eventSourcing - #symfonyCat
We broke up with the monolith, and started dating #eventSourcing - #symfonyCatWe broke up with the monolith, and started dating #eventSourcing - #symfonyCat
We broke up with the monolith, and started dating #eventSourcing - #symfonyCat
 
GraphQL in Symfony
GraphQL in SymfonyGraphQL in Symfony
GraphQL in Symfony
 
apidays LIVE New York 2021 - Introduction to HATEOAS with Ketting by Evert Po...
apidays LIVE New York 2021 - Introduction to HATEOAS with Ketting by Evert Po...apidays LIVE New York 2021 - Introduction to HATEOAS with Ketting by Evert Po...
apidays LIVE New York 2021 - Introduction to HATEOAS with Ketting by Evert Po...
 
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API DocumentationNordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API Documentation
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
 
Altitude SF 2017: Building a continuous deployment pipeline
Altitude SF 2017: Building a continuous deployment pipelineAltitude SF 2017: Building a continuous deployment pipeline
Altitude SF 2017: Building a continuous deployment pipeline
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConfFull-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
 
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java GirlFull-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
 

Viewers also liked

Mills Fitness Inc: More than a Brand of Health
Mills Fitness Inc:  More than a Brand of HealthMills Fitness Inc:  More than a Brand of Health
Mills Fitness Inc: More than a Brand of Health
David Mills
 

Viewers also liked (17)

DDOS Protected VPS
DDOS Protected VPSDDOS Protected VPS
DDOS Protected VPS
 
gary resume 2016
gary resume 2016gary resume 2016
gary resume 2016
 
Mills Fitness Inc: More than a Brand of Health
Mills Fitness Inc:  More than a Brand of HealthMills Fitness Inc:  More than a Brand of Health
Mills Fitness Inc: More than a Brand of Health
 
PHPCon Poland 2015 - Jak stać się lepszym programistą - Jerzy Zawadzki
PHPCon Poland 2015 - Jak stać się lepszym programistą - Jerzy ZawadzkiPHPCon Poland 2015 - Jak stać się lepszym programistą - Jerzy Zawadzki
PHPCon Poland 2015 - Jak stać się lepszym programistą - Jerzy Zawadzki
 
Yogesh CV
Yogesh CVYogesh CV
Yogesh CV
 
Dedicated sever collocation
Dedicated sever collocationDedicated sever collocation
Dedicated sever collocation
 
JSON support in Java EE 8
JSON support in Java EE 8JSON support in Java EE 8
JSON support in Java EE 8
 
What’s new in JSR 367 Java API for JSON Binding
What’s new in JSR 367 Java API for JSON BindingWhat’s new in JSR 367 Java API for JSON Binding
What’s new in JSR 367 Java API for JSON Binding
 
メールシステムのおはなし #Mailerstudy
メールシステムのおはなし #Mailerstudyメールシステムのおはなし #Mailerstudy
メールシステムのおはなし #Mailerstudy
 
Tecno treball eines
Tecno treball einesTecno treball eines
Tecno treball eines
 
Naresh_resume_23Aug
Naresh_resume_23AugNaresh_resume_23Aug
Naresh_resume_23Aug
 
JSON Support in Java EE 8
JSON Support in Java EE 8JSON Support in Java EE 8
JSON Support in Java EE 8
 
OpenStack Heat Orchestration
OpenStack Heat OrchestrationOpenStack Heat Orchestration
OpenStack Heat Orchestration
 
финансовый рынок 01_03_2016 (2)
финансовый рынок 01_03_2016 (2)финансовый рынок 01_03_2016 (2)
финансовый рынок 01_03_2016 (2)
 
финансовый рынок 01.09.2015
финансовый рынок 01.09.2015финансовый рынок 01.09.2015
финансовый рынок 01.09.2015
 
финансовый рынок 01.06.2015
финансовый рынок 01.06.2015финансовый рынок 01.06.2015
финансовый рынок 01.06.2015
 
дайджест сэр 2015_март_2016_n_1_9
дайджест сэр 2015_март_2016_n_1_9дайджест сэр 2015_март_2016_n_1_9
дайджест сэр 2015_март_2016_n_1_9
 

Similar to Vaugham Hong - Embedding JavaScript V8

Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
scdhruv5
 

Similar to Vaugham Hong - Embedding JavaScript V8 (20)

Old code doesn't stink
Old code doesn't stinkOld code doesn't stink
Old code doesn't stink
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
Game of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GCGame of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GC
 
Dino2 - the Amazing Evolution of the VA Smalltalk Virtual Machine
Dino2 - the Amazing Evolution of the VA Smalltalk Virtual MachineDino2 - the Amazing Evolution of the VA Smalltalk Virtual Machine
Dino2 - the Amazing Evolution of the VA Smalltalk Virtual Machine
 
Nsc 2013 06-17 - random rants on 2013
Nsc 2013 06-17 - random rants on 2013Nsc 2013 06-17 - random rants on 2013
Nsc 2013 06-17 - random rants on 2013
 
Old code doesn't stink - Detroit
Old code doesn't stink - DetroitOld code doesn't stink - Detroit
Old code doesn't stink - Detroit
 
Web前端性能优化 2014
Web前端性能优化 2014Web前端性能优化 2014
Web前端性能优化 2014
 
SignalR and GroomingPoker
SignalR and GroomingPokerSignalR and GroomingPoker
SignalR and GroomingPoker
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5
 
Google web toolkit gwt training
Google web toolkit gwt trainingGoogle web toolkit gwt training
Google web toolkit gwt training
 
SFScon 2020 - Davide Vernassa - Customize your data visualizations with KNOWAGE
SFScon 2020 - Davide Vernassa - Customize your data visualizations with KNOWAGESFScon 2020 - Davide Vernassa - Customize your data visualizations with KNOWAGE
SFScon 2020 - Davide Vernassa - Customize your data visualizations with KNOWAGE
 
Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)
Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)
Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
 
Learning JavaScript Programming
Learning JavaScript ProgrammingLearning JavaScript Programming
Learning JavaScript Programming
 
Serverless SQL
Serverless SQLServerless SQL
Serverless SQL
 
Case Study: Porting a set of point cloud and triangle mesh processing C++ lib...
Case Study: Porting a set of point cloud and triangle mesh processing C++ lib...Case Study: Porting a set of point cloud and triangle mesh processing C++ lib...
Case Study: Porting a set of point cloud and triangle mesh processing C++ lib...
 
Making ultra fast ultra scalable solutions with sitecore 8
Making ultra fast ultra scalable solutions with sitecore 8Making ultra fast ultra scalable solutions with sitecore 8
Making ultra fast ultra scalable solutions with sitecore 8
 
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 Harness SharePoint and jQuery to Make Dynamic Displays and Applications Harness SharePoint and jQuery to Make Dynamic Displays and Applications
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

Vaugham Hong - Embedding JavaScript V8