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
Alex Navasardyan
August 26, 2014
Programming
1
49
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
90
Ember List View
twokul
0
58
Other Decks in Programming
See All in Programming
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
380
AIでLINEスタンプを作ってみた
eycjur
1
230
[FEConf 2025] 모노레포 절망편, 14개 레포로 부활하기까지 걸린 1년
mmmaxkim
0
1.5k
Jakarta EE Core Profile and Helidon - Speed, Simplicity, and AI Integration
ivargrimstad
0
360
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
360
速いWebフレームワークを作る
yusukebe
5
1.7k
AWS発のAIエディタKiroを使ってみた
iriikeita
1
170
DockerからECSへ 〜 AWSの海に出る前に知っておきたいこと 〜
ota1022
5
1.9k
Ruby Parser progress report 2025
yui_knk
1
300
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
2
1.3k
The state patternの実践 個人開発で培ったpractice集
miyanokomiya
0
160
Design Foundational Data Engineering Observability
sucitw
3
170
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
A better future with KSS
kneath
239
17k
Designing for humans not robots
tammielis
253
25k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.2k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Statistics for Hackers
jakevdp
799
220k
Docker and Python
trallard
45
3.5k
Navigating Team Friction
lara
189
15k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
How to Ace a Technical Interview
jacobian
279
23k
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!