Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
V8
Search
dimko1
September 13, 2015
Programming
0
260
V8
How V8 Works
dimko1
September 13, 2015
Tweet
Share
More Decks by dimko1
See All by dimko1
Anti-patterns
dimko1
0
43
JS under the hood
dimko1
0
190
Other Decks in Programming
See All in Programming
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
370
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
930
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
960
Elm Form Validation
bkuhlmann
0
510
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
530
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.3k
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
270
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
180
Code Reviews
bkuhlmann
4
890
ゆるい個人開発のススメ
kuroppe1819
10
990
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
230
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
1
160
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
121
39k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
We Have a Design System, Now What?
morganepeng
43
6.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
Building a Scalable Design System with Sketch
lauravandoore
456
32k
StorybookのUI Testing Handbookを読んだ
zakiyama
13
4.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
25
2.3k
Designing Experiences People Love
moore
136
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
19
1.7k
Product Roadmaps are Hard
iamctodd
44
9.7k
Transcript
V8 by @dimko1
What? • Googles Open Source Engine • Written on C++
• Compiles JS into Machine Code at execution (JIT) without producing byte code • Powers Chrome, Node, Opera • Can run standalone, or can be embedded into any C++ program
Made in Germany
None
So, why to know? • Have no idea:)
Demo
Hidden Classes • We don’t have types. (oh c’mon, not
about primitives) • To optimise we need types… • Types information is valuable for code generation • Remember: Compilation during Execution
Hidden Classes help to run faster • Creating hidden classes
for objects during run- time • Objects with same hidden class can use same optimised code
None
None
Summary • Initialise all members in construction function • Initialise
members in same order
Tagging • V8 represent JavaScript objects with 32 bits values
• Object has flag 1 • Integer has flag 0 and called SMI • If bigger - turning it into double and create new object
None
Summary • Prefer numeric values that can be represented as
31-bit integer
Arrays • We have arrays, huge array and sparse arrays
• Two ways of representing arrays: • Fast Elements • Dictionary Elements
Summary • Create arrays from 0 index :) • Don’t
pre-allocate large Arrays • Don’t delete element from array • Don't load uninitialized or deleted elements
None
None
None
Summary 2 • User Array Literal: var a = [77,
88, 0.5, true] • Don’t store non numeric values in numeric arrays
Compilers • “Full” compiler can generate good code for any
JavaScript • Optimizing compiler produces great code for most JavaScript
Full Compiler • Generate code quickly • Does do no
type analysis • Using Inline Caching. Gather type information in runtime
How Inline Cache Works • Type dependant code for operations
• Validate type assumptions first • Change at runtime as more types discovered
None
None
None
Monomorphic better than Polymorphic
Optimizing Compiler • Comes later and re-compiles “hot” functions •
Types taken form ICs • Monomorphic can be inlined • Inlining enables other optimizations
None
None
Deoptimization • Optimization are speculative • Throws away optimized code
• Resumes execution at the right place • Reoptimization might be triggered again later
Summary • Avoid changes in the hidden classes after functions
were optimised
What is a problem now? • Ensure problem is in
JS • Reduce to pure JS ( not DOM ) • Collect metrics
Demo
?