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
And Benchmarks For All
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Alex Navasardyan
August 26, 2014
Programming
1
51
And Benchmarks For All
A talk about browsers, JavaScript, V8 and compilers.
Alex Navasardyan
August 26, 2014
Tweet
Share
More Decks by Alex Navasardyan
See All by Alex Navasardyan
Ember App Kit
twokul
0
49
Ember Data
twokul
0
93
Ember List View
twokul
0
58
Other Decks in Programming
See All in Programming
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
CSC307 Lecture 04
javiergs
PRO
0
660
CSC307 Lecture 03
javiergs
PRO
1
490
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
280
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
260
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
170
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
Fluid Templating in TYPO3 14
s2b
0
130
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
Featured
See All Featured
Between Models and Reality
mayunak
1
190
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Ethics towards AI in product and experience design
skipperchong
2
190
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
340
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
Optimizing for Happiness
mojombo
379
71k
The Language of Interfaces
destraynor
162
26k
We Have a Design System, Now What?
morganepeng
54
8k
Utilizing Notion as your number one productivity tool
mfonobong
3
220
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
120
Transcript
And Benchmarks For All
How to be faster and keep the pace.
Alex Navasardyan @twokul
None
What is a Benchmark?
the act of running a computer program, in order to
assess the relative performance of an object.
Benchmark is a Measurement
What are you measuring?
@SciencePorn
History
1991 Getto JavaScript
2006 jQuery/Dojo/MooTools
jQuery vs. Dojo http://jsperf.com/mojo-of-dojo-and-jquery is jQuery better than Dojo? why
use Dojo? Dojo: Twice As Fast When It Matters Most?
None
2009 node.js
2011 Embularactymerbone
Sane Code Structure
Modules
Sane Code Tools
Build tools
Know your tools
Chrome Dev Tools
None
D8 + IRHydra 2
None
None
Perf linter?
V8
Spider Monkey
Chakra
The code that you write is not the code that
gets executed.
Vocabulary (for V8)
• Bailouts. • Deoptimizations. • Oddballs (undefined, true, null). •
Monomorphic, Polymorphic.
Hidden classes (or maps)
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83;
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83;
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83; Class C0
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83; Class C1:C0
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83; Class C2:C1
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83; Class C2:C1
function Person(first, last) { this.firstName = first; this.lastName = last;
} ! var ironMan = new Person(‘Tony’, ‘Stark’); var captainAmerica = new Person(‘Steve’, ‘Rogers’); captainAmerica.age = 83; Class C3:C2
• initialize object members in constructor functions. • always initialize
object members in the same order (different hidden class trees).
Numbers (and tagging)
• 32 bit are used to represent both a number
and an object (to use the same code path). • last bit is 0 (number), 31 bit signed integer. • last bit is 1 (object). • if bigger than 31 bit, it creates a pointer to a new object.
• use 31 bit signed integers to avoid boxing.
Arrays (and objects)
• Fast Elements, linear storage buffer. • Dictionary Elements, hash
table storage.
• use contiguous index starting at 0. • don’t preallocate
large arrays. • don’t delete elements in arrays. • use array literals.
Compilers
• Full Compiler. • Optimizing Compiler, Crankshaft.
Inline Cache (optimization)
var ironMan = new Person(‘Tony’, ‘Stark’); ! console.log(ironMan.firstName);
push [ebp+0x8] mov eax,[ebp+0xc] mov edx, eax mov ecx, 0x60b55dd1
call LoadIC_Initialize ;; ironMan.firstName
push [ebp+0x8] mov eax,[ebp+0xc] mov edx, eax mov ecx, 0x60b55dd1
call 0x311286e0 ;; ironMan.firstName
More optimizations
var a = “12342234”, b, start = Date.now(); ! for
(var i = 0; i < 1000; i++) { b = ~~a; } ! console.log(Date.now() - start); Convert string to a number
var a, b, start = Date.now(); ! for (var i
= 0; i < 1000; i++) { b = ~~“12342234”; } ! console.log(Date.now() - start); Inlines the string
var a, b, start = Date.now(); ! for (var i
= 0; i < 1000; i++) { b = 12342234; } ! console.log(Date.now() - start); Inlines the converted value
var a, b, start = Date.now(); ! for (var i
= 0; i < 1000; i++) { // benchmarking the assignment b = 12342234; } ! console.log(Date.now() - start); Constant Propagation
var a = Date.now().toString(); var b, start = Date.now(); !
for (var i = 0; i < 1000; i++) { b = ~~a; } ! console.log(Date.now() - start); Convert string to a number
var a = Date.now().toString(); var b, start = Date.now(); !
var c = ~~a; for (var i = 0; i < 1000; i++) { b = c; } ! console.log(Date.now() - start); Hoists the conversion
var a = Date.now().toString(); var b, start = Date.now(); !
var c = ~~a; for (var i = 0; i < 1000; i++) { // benchmarking the assignment b = c; } ! console.log(Date.now() - start); Loop Invariant Motion
var start = Date.now(); ! for (var i = 0;
i < 1000; i++) { // happy benchmarking } ! console.log(Date.now() - start); Dead Code Elimination
var add = function(a, b, c, d) { return a
+ b + c + d; }; ! for (var i = 0; i < 1000; i++) { add(“a”, “b”, “c”, “d"); } Function inlining
for (var i = 0; i < 1000; i++) {
“a” + “b” + “c” + “d” } Function inlining
for (var i = 0; i < 1000; i++) {
“a” + “b” + “c” + “d” } ! for (var i = 0; i < 1000; i++) { // happy benchmarking } Benchmarking inlining
Algorithmic
The power of your optimization comes from right data structures
and algorithms.
Fix what matters
Benchmarks tips
• leave your laptop plugged in. • close all running
applications. • be prepared for the results to be inconsistent.
Thanks!