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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
560
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
460
Oxlintはいいぞ
yug1224
5
1.3k
SourceGeneratorのススメ
htkym
0
200
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
610
AI時代の認知負荷との向き合い方
optfit
0
160
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
0
81
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
KATA
mclloyd
PRO
34
15k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Cult of Friendly URLs
andyhume
79
6.8k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
91
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
Accessibility Awareness
sabderemane
0
51
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
The Curious Case for Waylosing
cassininazir
0
230
WCS-LA-2024
lcolladotor
0
450
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!