jsmeter: characterizing the behavior of javascript web...
TRANSCRIPT
![Page 1: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/1.jpg)
Paruj Ratanaworabhan Kasetsart University, Thailand
Ben Livshits and Ben Zorn Microsoft Research, Redmond
JSMeter: Characterizing the Behavior of JavaScript Web Applications
1
in collaboration with
David Simmons, Corneliu Barsan, and Allen Wirfs-Brock
![Page 2: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/2.jpg)
One Word:
2
JavaScript
Standard for scripting web applications
Fast JITs widely available
Support in every browser
Lots of code present
in all major web sites
![Page 3: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/3.jpg)
4
ZDNet 29 May 2008
ghacks.net Dec. 2008
Browser
Wars!
![Page 4: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/4.jpg)
Artificial Benchmarks versus Real World Sites
5
Maps Maps
7 V8 programs:
• richards
• deltablue
• crypto
• raytrace
• earley-boyer
• regexp
• splay
8 SunSpider programs:
• 3-draytrace
• access-nbody
• bitops-nsieve
• controlflow
• crypto-aes
• date-xparb
• math-cordic
• string-tagcloud
JSMeter 11 real sites:
Goals of this Talk
• Show behavior of JavaScript benchmarks versus real sites
• Consider how benchmarks can mislead design decisions
![Page 5: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/5.jpg)
6
Instrumentation Framework
\ie\jscript\*.cpp
Source-level instrumentation
custom jscript.dll
custom trace files website visits
Offline analyzers
custom trace files
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
Constant
Other Str Ops
Concat Op
![Page 6: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/6.jpg)
Visiting the Real Sites
• Getting past page load performance
• Attempted to use each site in “normal” way:
7
amazon Search a book, add to shopping cart, sign in, and sign out bing Type in a search query and also look for images and news bingmap Search for a direction from one city to another cnn Read front page news ebay Search for a notebook, bid, sing in, and sign out economist Read front page news, view comments facebook Log in, visit a friend pages, browse through photos and comments gmail Sign in, check inbox, delete a mail, and sign out google Type in a search query and also look for images and news googlemap Search for a direction from one city to another hotmail Sign in, check inbox, delete a mail, and sign out
![Page 7: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/7.jpg)
Understanding JavaScript Behavior
Code
Events
JavaScript
Objects
8
![Page 8: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/8.jpg)
Code Behavior
Code
Events
JavaScript
Objects
9
• Function size
• Instructions/call
• Code locality
• Instruction mix
![Page 9: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/9.jpg)
Total Bytes of JavaScript Source
10
0
500
1000
1500
2000
2500
am
azon
bin
g
bin
gm
ap
cnn
ebay
econom
ist
gm
ail
map
hotm
ail
richard
s
delt
ablu
e
cry
pto
raytr
ace
earl
ey
regexp
spla
y
3d-ra
ytr
ace
access-nbody
bit
ops-nsie
ve
contr
olf
low
cry
pto
-aes
date
-xparb
math
-cord
ic
regexp-dna
str
ing-ta
gclo
ud
Sourc
e s
ize (kilobyte
s)
Real Sites V8 SunSpider
Code|Objects|Events
![Page 10: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/10.jpg)
Static Unique Functions Executed
12
0
500
1,000
1,500
2,000
2,500
3,000
3,500
4,000am
azon
bin
g
bin
gm
ap
cnn
ebay
econom
ist
gm
ail
map
hotm
ail
richard
s
delt
ablu
e
cry
pto
raytr
ace
earl
ey
regexp
spla
y
3d-ra
ytr
ace
access-nbody
bit
ops-nsie
ve
contr
olf
low
cry
pto
-aes
date
-xparb
math
-cord
ic
regexp-dna
str
ing-ta
gclo
ud
Uniq
ue F
uncti
ons E
xecute
d
Real Sites V8 SunSpider
Code|Objects|Events
![Page 11: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/11.jpg)
Bytecodes / Call
15
0.00
50.00
100.00
150.00
200.00
250.00
300.00
am
azon
bin
g
bin
gm
ap
cnn
ebay
econom
ist
gm
ail
map
hotm
ail
richard
s
delt
ablu
e
cry
pto
raytr
ace
earl
ey
regexp
spla
y
3d-ra
ytr
ace
access-nbody
bit
ops-nsie
ve
contr
olf
low
cry
pto
-aes
date
-xp
arb
math
-cord
ic
regexp-dna
str
ing-ta
gclo
ud
Byte
codes /
Call
function(a,b) { var i=0,elem,pos=a.length; if(D.browser.msie) { while(elem=b[i++]) if(elem.nodeType!=8) a[pos++]=elem; } else while(elem=b[i++]) a[pos++]=elem; return a }
Real Sites V8 SunSpider
Code|Objects|Events
![Page 12: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/12.jpg)
Fraction of Code Executed
16
0.00%
10.00%
20.00%
30.00%
40.00%
50.00%
60.00%
70.00%
80.00%
90.00%
100.00%
am
azon
bin
g
bin
gm
ap
cnn
ebay
econom
ist
gm
ail
map
hotm
ail
richard
sdelt
ablu
e
cry
pto
raytr
ace
earl
ey
regexp
spla
y
3d-ra
ytr
ace
access-nbody
bit
ops-nsie
ve
contr
olf
low
cry
pto
-aes
date
-xparb
math
-cord
ic
regexp-dna
str
ing-ta
gclo
ud
Fra
cti
on o
f C
ode E
xecute
d
Most code
not executed
Real Sites V8 SunSpider
Code|Objects|Events
![Page 13: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/13.jpg)
Hot Function Distribution
17
Real Sites V8 Benchmarks
80% of time in < 10 functions 80% of time in 100+ functions
80% 80%
Code|Objects|Events
![Page 14: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/14.jpg)
Opcode Distribution
18 Green = SunSpider | Blue= Real Web Apps | Red = V8
Real Apps
Outliers
Code|Objects|Events
![Page 15: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/15.jpg)
Object Allocation Behavior
Code
Events
JavaScript
Objects
19
• Allocation by types
• Lifetime distribution
• Live heap composition
![Page 16: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/16.jpg)
Total Bytes Allocated
20
0
5000
10000
15000
20000
25000
30000
35000
40000
45000
am
azon
bin
g
bin
gm
ap
cnn
ebay
econom
ist
gm
ail
map
hotm
ail
richard
s
delt
ab
lue
cry
pto
raytr
ace
earl
ey
regexp
spla
y
3d-ra
ytr
ace
access-nbody
bit
ops-nsie
ve
contr
olf
low
cry
pto
-aes
date
-xparb
math
-cord
ic
regexp-dna
str
ing-ta
gclo
ud
Tota
l heap
data
(kilobyte
s)
Real Sites V8 SunSpider
Code|Objects|Events
![Page 17: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/17.jpg)
Heap Data by Type
21
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
amaz
on
bin
gb
ingm
ap cnn
ebay
eco
no
mis
tfa
ceb
oo
kgm
ail
goo
gle
goo
glem
aph
otm
ail
rich
ard
sd
elta
blu
ecr
ypto
rayt
race
earl
eyre
gexp
spla
yV
8 a
ggra
gate
3d
-ray
trac
eac
cess
-nb
od
yb
ito
ps-
nsi
eve
con
tro
lflo
wcr
ypto
-aes
dat
e-xp
arb
mat
h-c
ord
icre
gexp
-dn
ast
rin
g-ta
gclo
ud
aggr
egat
e
He
ap D
ata
by
Typ
e
Objects
Enumarator
RegExp
Math
Error
Date
Native Func
String
Arrays
Script Func
Real Sites V8 SunSpider
Many functions
Rest are strings
Few benchmarks
allocate much data
Code|Objects|Events
![Page 18: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/18.jpg)
Live Heap Over Time (gmail)
23
Functions grow
steadily
Code|Objects|Events
GC reduces
size of heap
Objects grow
steadily too
![Page 19: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/19.jpg)
Live Heap over Time (ebay)
24
Heaps
repeatedly
created,
discarded
Heap contains
mostly functions
Code|Objects|Events
Heap drops to 0
on page load
![Page 20: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/20.jpg)
2 Search Websites, 2 Architectures
Bing
(Web 2.0)
(Web 1.0)
Code|Objects|Events
25
You stay on the same page
during your entire visit
Code loaded once
Heap is bigger
Every transition loads a
new page
Code loaded repeatedly
Heap is smaller
![Page 21: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/21.jpg)
Event Handlers in JavaScript
Code
Events
JavaScript
Objects
29
• Number of events • Sizes of handlers
![Page 22: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/22.jpg)
Event-driven Programming Model
• Single-threaded, non-preemptive event handlers
• Example handlers: onabort, onclick, etc.
• Very different from batch processing of benchmarks
• Handler responsiveness critical to user experience
30
Code|Objects|Events
![Page 23: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/23.jpg)
Total Events Handled
31
0
1,000
2,000
3,000
4,000
5,000
6,000
7,000T
ota
l Events
Handle
d
Real Sites V8
Almost no events
Code|Objects|Events
![Page 24: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/24.jpg)
Median Bytecodes / Event Handled
33
0
50
100
150
200
250
300
350
400
450
500M
edia
n B
yte
codes /
Event
Hand
led
Code|Objects|Events
506 2137
![Page 25: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/25.jpg)
Cold-code Experiment
• Observation
– Real web apps have lots of code (much of it cold)
– Benchmarks do not
• Question: What happens if the benchmarks have more code?
– We added extra, unused to code to 6 SunSpider benchmarks
– We measured the impact on the benchmark performance
37
![Page 26: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/26.jpg)
Performance Impact of Cold Code
38
0
100
200
300
400
500
600
700
800
900
Tim
e (
mse
c)
0K
200K
400K
800K
1M
2M
0
100
200
300
400
500
600
700
800
900
Tim
e (
mse
c)
0K
200K
400K
800K
1M
2M
Chrome IE 8
Cold code has
non-uniform impact
on execution time
Without cold code,
Chrome12x faster than IE8 With 2M cold code,
Chrome 4.7x faster than IE8
Which comparison is more meaningful?
Cold code makes
SunSpider on Chrome
up to 4.5x slower
![Page 27: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/27.jpg)
Impact of Benchmarks
• What gets emphasis
– Making tight loops fast
– Optimizing small amounts of code
• Important issues ignored
– Garbage collection (especially of strings)
– Managing large amounts of code
– Optimizing event handling
– Considering JavaScript context between page loads
39
![Page 28: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/28.jpg)
Conclusions • JSmeter is an instrumentation framework
– Used to measure and compare JavaScript applications
– High-level views of behavior promote understanding
• Benchmarks differ significantly from real sites
– Misleads designers, skews implementations
• Next steps
– Develop and promote better benchmarks
– Design and evaluate better JavaScript runtimes
– Promote better performance tools for JavaScript developers
40
![Page 29: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/29.jpg)
Conclusions
• JSmeter is an instrumentation framework
– Used to measure and compare JavaScript applications
– High-level views of behavior promote understanding
• Behavior in benchmarks significantly differs from real sites
– Misleads designers, skews implementations
• Next steps
– Develop and promote better benchmarks
– Design and evaluate better JavaScript runtimes
– Promote better performance tools for JavaScript developers
41
![Page 30: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/30.jpg)
Additional Resources
• Project: http://research.microsoft.com/en-us/projects/jsmeter/
• Video: Project JSMeter: JavaScript Performance Analysis in the Real World" - MSDN Channel 9 interview with Erik Meier, Ben Livshits, and Ben Zorn
• Papers:
– “JSMeter: Comparing the Behavior of JavaScript Benchmarks with Real Web Applications”, Paruj Ratanaworabhan, Benjamin Livshits and Benjamin G. Zorn, USENIX 2010 Conference on Web Application Development (WebApps’10), June 2010.
– "JSMeter: Characterizing Real-World Behavior of JavaScript Programs", Paruj Ratanaworabhan, Benjamin Livshits, David Simmons, and Benjamin Zorn, MSR-TR-2009-173, December 2009 (49 pages), November 2009.
42
![Page 31: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/31.jpg)
Additional Slides
43
![Page 32: JSMeter: Characterizing the Behavior of JavaScript Web …livshits/papers/ppt/JSMeter-WebApps10.pdf · 2017-01-10 · JSMeter: Characterizing the Behavior of JavaScript Web Applications](https://reader033.vdocuments.net/reader033/viewer/2022041723/5e501f9b5f7357430f64fd72/html5/thumbnails/32.jpg)
Related Work
• JavaScript
– “An Analysis of the Dynamic Behavior of JavaScript Programs”, Gregor Richards, Sylvain Lebresne, Brian Burg, Jan Vitek, PLDI 2010, June 2010/
• C# and Java
– Doufour
• C++
– Calder et al.
44