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
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エージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
5
450
CSC307 Lecture 04
javiergs
PRO
0
660
Fluid Templating in TYPO3 14
s2b
0
130
Architectural Extensions
denyspoltorak
0
280
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
280
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
280
AI巻き込み型コードレビューのススメ
nealle
1
210
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Docker and Python
trallard
47
3.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Accessibility Awareness
sabderemane
0
51
Context Engineering - Making Every Token Count
addyosmani
9
650
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
120
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
65
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Building Applications with DynamoDB
mza
96
6.9k
Scaling GitHub
holman
464
140k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
80
The Spectacular Lies of Maps
axbom
PRO
1
520
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!