SlideShare a Scribd company logo
1 of 18
WebGL 
and web site 
performance 
Tony Parisi 
September, 2014
disclaimer 
I’m not a perf guy. 
but I am perf-curious. 
and I teach the world about WebGL. 
so I need to figure this out. 
why? 
WebGL devs need to understand high performance web site 
development 
the world is watching and there are lots of examples out there with 
bad perf practices 
we have an opportunity to add WebGL to the perf testing canon 
http://www.tonyparisi.com 9/17/2014
about me 
http://www.meetup.com/WebGL-Developers-Meetup/ 
creds 
Co-creator, VRML and X3D 
work 
http://www.vizi.gl/ 
get GLAM 
http://www.glamjs.org/ 
https://github.com/tparisi/glam/ 
get VIZI 
https://github.com/tparisi/Vizi 
contact information 
tparisi@gmail.com 
skype: auradeluxe 
http://twitter.com/auradeluxe htt 
p://www.tonyparisi.com/ 
http://www.learningwebgl.com/ 
SF WebGL Meetup 
SF WebVR Meetup 
http://www.meetup.com/Web-VR/ 
book source code 
https://github.com/tparisi/WebGLBook 
https://github.com/tparisi/Programming3DApplications 
get the books! 
WebGL: Up and Running 
http://www.amazon.com/dp/144932357X 
Programming 3D Applications with HTML and WebGL 
http://www.amazon.com/Programming-Applications- 
HTML5-WebGL-Visualization/dp/1449362966 http://www.tonyparisi.com 9/17/2014
performance savior… 
or scourge? 
SAVIOR… 
WebGL brings the power of the GPU to the web 
WebGL means no 3D plugins 
WebGL pioneered Typed Arrays: compact binary data for web 
applications 
WebGL has no DOM – no CSS or layout impact 
or SCOURGE? 
WebGL has no DOM – scripts required to see anything on the 
screen. lots of script code… LOTS. 
WebGL requires shaders – text programs that result in 
additional requests and client-side load/compile time 
WebGL pulls more content down the pipe 
WebGL apps tend toward full-screen… more front page content 
WebGL SUCKS… CPU (if you’re not careful) 
http://www.tonyparisi.com 9/17/2014
the anatomy of a WebGL 
application 
1. create a <canvas> element and obtain 
a WebGL drawing context 
var ctx= canvas.getContext(“webgl”); 
2. load JavaScript setup code 
a. initialize viewport 
b. create buffers 
c. create matrices 
d. load texture maps 
3. download and compile/link shaders 
4. draw 
http://www.tonyparisi.com 9/17/2014
first render 
no scripts… 
no pics. 
http://www.tonyparisi.com 9/17/2014
shaders 
GLSL (Open GL Shader Language) – C-like language compiled 
onto the GPU and executed to position each vertex and paint 
each pixel. REQUIRED TO SEE ANYTHING ON THE SCREEN. 
var vertexShaderSource = 
" attribute vec3 vertexPos;n" + 
" attribute vec2 texCoord;n" + 
" uniform mat4 modelViewMatrix;n" + 
" uniform mat4 projectionMatrix;n" + 
" varying vec2 vTexCoord;n" + 
" void main(void) {n" + 
" // Return the transformed and projected vertex valuen" + 
" gl_Position = projectionMatrix * modelViewMatrix * n" + 
" vec4(vertexPos, 1.0);n" + 
" // Output the texture coordinate in vTexCoordn" + 
" vTexCoord = texCoord;n" + 
" }n"; 
var fragmentShaderSource = 
" precision mediump float;n" + 
" varying vec2 vTexCoord;n" + 
" uniform sampler2D uSampler;n" + 
" void main(void) {n" + 
" // Return the pixel color: always output whiten" + 
" gl_FragColor = texture2D(uSampler, vec2(vTexCoord.s, vTexCoord.t));n" + 
"}n"; 
the vertex shader 
transforms model-space 
positions into screen 
space 
the fragment shader 
outputs a color value 
for each pixel 
http://www.tonyparisi.com 9/17/2014
more stuff to load (1) 
shader source code 
from Anton Gerdelan’s “Loading Shaders from 
Files with Ajax” 
http://antongerdelan.net/webgl/shadersandajax. 
html 
more files == more 
requests 
after download, this 
compile/link step 
consumes additional 
client side cycles 
http://www.tonyparisi.com 9/17/2014
more stuff to load (2) 
JavaScript libraries 
programming WebGL to the metal not very productive; 
most people use an engine library 
Three.js – very popular 3D rendering engine 
430k minified 
Tween.js – tweening (simple animation) 
5k! nice 
more code from there – game engines, frameworks, app 
templates… 
it can get big. but we minify, compress, and defer loading. 
thus has it ever been. 
http://www.tonyparisi.com 9/17/2014
more stuff to load (3) 
texture maps 
bitmaps applied to the surfaces of 
3D objects 
image sprite-type techniques 
can help 
CSS sprites not supported 
directly 
one texture map can be used for 
several 3D objects – saves both 
download time and rendering 
time – but utility is limited to 
certain situations 
bigger savings will be in 
compressed, fast to load texture 
formats like DDS (currently in a 
WebGL extension) 
surface details of 
various parts, or even 
different objects, can 
be packed into a single 
image 
http://www.tonyparisi.com 9/17/2014
more stuff to load (4) 
3D models and scenes 
reminder: WebGL is an API. no file format. no DOM. 
current state of practice is to load JSON, or JSON + binary data in typed 
array (non-standard format) 
some apps use (shudder) XML 3D data description like COLLADA (“just 
server-side GZIP it, what’s the big deal…?”) 
new format: glTF 
http://www.gltf.gl/ 
a “JPEG for 3D” 
Khronos group initiative – pre-standard, experimental 
compact, efficient to load representation of 3D data 
GL native data types require no additional processing – stored as Typed Arrays 
also includes common 3D scene constructs: object hierarchy, cameras, lights, 
common material types, animation 
all data for a scene can be packed into a single file (or multiple, it’s totally flexible) 
can be streamed 
http://www.tonyparisi.com 9/17/2014
what fold…? 
http://www.tonyparisi.com 9/17/2014 
full-screen apps are making a comeback… 
more content on the front page… and nothing below the fold to optimize.
what IS performance? (1) 
in games, fast run-time performance usually comes at the 
expense of large initial engine download 
pro game engine ports to WebGL are taking us back to the 
future 
Emscripten cross-compiled C++ to asm.js (low-level assembly-style 
JavaScript) – really fast and not leaky 
resulting JavaScript is HUGE – 10Mb+ http://www.tonyparisi.com 9/17/2014
what IS performance? (2) 
what happens after first 
render? we could be 
creating a high-performance 
way to deliver perf hogs… 
WebGL apps can be 
CPU-suckers! lots of 
computation needs to be 
done on CPU 
JavaScript engines tend 
to be greedy… 
new Page Visibility API 
can help (but it doesn’t 
tell you when a window 
is occluded…) 
http://www.tonyparisi.com 9/17/2014 
! gah !
some things to try 
inline shaders (defeats caching) 
pack shaders, unpack on client 
defer loading library code – start with small head end 
pack textures 
use DDS textures when the format becomes available (WebGL 2?) 
use procedural textures and geometry 
defer 3D content loading – load on navigate, visibility, combine with 
prediction 
use CSS3 3D transforms for front page/load screen – they are 
hardware-accelerated and can be rendered before scripts are 
loaded 
http://www.tonyparisi.com 9/17/2014
WebGL sites: some perf 
tests 
WebGL showcase sites not optimized 
not sure end users care… these are showcases 
but View Source and copy-paste could spread bad practices 
pro sites showing mixed results 
but this could be similar to the distribution in non-WebGL 
sites… 
http://www.tonyparisi.com 9/17/2014
making today’s perf tests 
WebGL-aware 
search DOM for canvas elements and WebGL patterns 
var c = document.createElement("canvas"); 
var gl1 = c.getContext("webgl"); // return WebGL context 
var ctx2d = c.getContext("2d"); // returns NULL. Canvas cannot have 
multiple context types. 
var gl2 = c.getContext("experimental-webgl"); // returns gl1. Browser 
treats experimental-webgl as an alias for webgl 
if succeeds then either (a) it’s already being used for WebGL or (b) 
false positive: uninitialized canvas 
look for inclusion of popularly used WebGL libraries like 
Three.js, Babylon.js, glMatrix… 
look for Ajaxing shader source files: .vs, .fs, .glsl 
look for Ajaxing popular model files: .stl, .obj, .dae, .gltf (soon) 
http://www.tonyparisi.com 9/17/2014
the state of things 
WebGL presents new perf challenges 
scripts required to see anything on the screen 
more stuff to load – shaders, JS libraries, textures, models 
full-screen apps make it hard to use above-the-fold techniques 
game engines might trade load time for run-time speed… will users 
tolerate it? 
performance doesn’t end at first render; apps need to watch resources 
once loaded 
WebGL devs need to start thinking about site performance 
WebGL moving from demo to deployment, so we should start to see 
good perf techniques (we better!) 
most WebGL developers are game devs or visualization experts… great 
at frame rate but need to learn web site perf 
we should investigate adding WebGL checks to standard perf tests 
http://www.tonyparisi.com 9/17/2014

More Related Content

Viewers also liked

EasyFilms LLC
EasyFilms LLCEasyFilms LLC
EasyFilms LLCEasyFilms
 
Leonor Pacheco Palomares
Leonor Pacheco PalomaresLeonor Pacheco Palomares
Leonor Pacheco PalomaresLeonor Pacheco
 
The Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game DevelopmentThe Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game DevelopmentTony Parisi
 
BillingViews Facebook Success Index
BillingViews Facebook Success IndexBillingViews Facebook Success Index
BillingViews Facebook Success IndexBillingViews
 
The right place for NFC
The right place for NFCThe right place for NFC
The right place for NFCBillingViews
 
Hair ton cream presentation
Hair ton cream presentationHair ton cream presentation
Hair ton cream presentationDr. Hani Malkawi
 
Sandra yurley garcía monet
Sandra yurley garcía monetSandra yurley garcía monet
Sandra yurley garcía monetCaro Spin
 
Hist oral la batalla de puebla 2
Hist oral la batalla de puebla 2Hist oral la batalla de puebla 2
Hist oral la batalla de puebla 2petryta
 
firefighting12
firefighting12firefighting12
firefighting12shelby93
 
Dog pile
Dog pileDog pile
Dog pilemcduyar
 
Seven barriers to payments
Seven barriers to paymentsSeven barriers to payments
Seven barriers to paymentsBillingViews
 
Mr Good MGD
Mr Good MGDMr Good MGD
Mr Good MGDJyeston
 
Instalacion windows-7
Instalacion windows-7Instalacion windows-7
Instalacion windows-7angeles104
 
Kompanihuset
KompanihusetKompanihuset
Kompanihusetfalster5
 
Insanityybest
InsanityybestInsanityybest
Insanityybestlindsayhb
 

Viewers also liked (20)

EasyFilms LLC
EasyFilms LLCEasyFilms LLC
EasyFilms LLC
 
Leonor Pacheco Palomares
Leonor Pacheco PalomaresLeonor Pacheco Palomares
Leonor Pacheco Palomares
 
Presentación Corporativa Gyga
Presentación Corporativa Gyga Presentación Corporativa Gyga
Presentación Corporativa Gyga
 
The Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game DevelopmentThe Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game Development
 
BillingViews Facebook Success Index
BillingViews Facebook Success IndexBillingViews Facebook Success Index
BillingViews Facebook Success Index
 
The right place for NFC
The right place for NFCThe right place for NFC
The right place for NFC
 
Hair ton cream presentation
Hair ton cream presentationHair ton cream presentation
Hair ton cream presentation
 
Sandra yurley garcía monet
Sandra yurley garcía monetSandra yurley garcía monet
Sandra yurley garcía monet
 
Hist oral la batalla de puebla 2
Hist oral la batalla de puebla 2Hist oral la batalla de puebla 2
Hist oral la batalla de puebla 2
 
firefighting12
firefighting12firefighting12
firefighting12
 
Gentanil booklet
Gentanil bookletGentanil booklet
Gentanil booklet
 
Service Desk by InfraManager ITSM
Service Desk by InfraManager ITSMService Desk by InfraManager ITSM
Service Desk by InfraManager ITSM
 
mallorca
mallorcamallorca
mallorca
 
Dog pile
Dog pileDog pile
Dog pile
 
Seven barriers to payments
Seven barriers to paymentsSeven barriers to payments
Seven barriers to payments
 
Mr Good MGD
Mr Good MGDMr Good MGD
Mr Good MGD
 
Instalacion windows-7
Instalacion windows-7Instalacion windows-7
Instalacion windows-7
 
Kompanihuset
KompanihusetKompanihuset
Kompanihuset
 
High School in the United States
High School in the United StatesHigh School in the United States
High School in the United States
 
Insanityybest
InsanityybestInsanityybest
Insanityybest
 

More from Tony Parisi

The New Fine Arts
The New Fine ArtsThe New Fine Arts
The New Fine ArtsTony Parisi
 
Face the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented WorldFace the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented WorldTony Parisi
 
Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17Tony Parisi
 
WebVR: Developing for the Immersive Web
WebVR: Developing for the Immersive WebWebVR: Developing for the Immersive Web
WebVR: Developing for the Immersive WebTony Parisi
 
Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Tony Parisi
 
WebVR Ecosystem and API Update
WebVR Ecosystem and API UpdateWebVR Ecosystem and API Update
WebVR Ecosystem and API UpdateTony Parisi
 
Foundations of the Immersive Web
Foundations of the Immersive WebFoundations of the Immersive Web
Foundations of the Immersive WebTony Parisi
 
The Immersive Web
The Immersive WebThe Immersive Web
The Immersive WebTony Parisi
 
Virtually Anyone
Virtually AnyoneVirtually Anyone
Virtually AnyoneTony Parisi
 
React-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR DevelopmentReact-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR DevelopmentTony Parisi
 
WebGL: The Next Generation
WebGL:  The Next GenerationWebGL:  The Next Generation
WebGL: The Next GenerationTony Parisi
 
Vrml, or There and Back Again
Vrml, or There and Back AgainVrml, or There and Back Again
Vrml, or There and Back AgainTony Parisi
 
The Coming Distribution War
The Coming Distribution WarThe Coming Distribution War
The Coming Distribution WarTony Parisi
 
Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015Tony Parisi
 
VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015Tony Parisi
 
An Introduction to Web VR January 2015
An Introduction to Web VR January 2015An Introduction to Web VR January 2015
An Introduction to Web VR January 2015Tony Parisi
 
Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014Tony Parisi
 
The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014Tony Parisi
 
Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5Tony Parisi
 
WebGL, WebVR and the Metaverse
WebGL, WebVR and the MetaverseWebGL, WebVR and the Metaverse
WebGL, WebVR and the MetaverseTony Parisi
 

More from Tony Parisi (20)

The New Fine Arts
The New Fine ArtsThe New Fine Arts
The New Fine Arts
 
Face the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented WorldFace the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented World
 
Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17
 
WebVR: Developing for the Immersive Web
WebVR: Developing for the Immersive WebWebVR: Developing for the Immersive Web
WebVR: Developing for the Immersive Web
 
Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016
 
WebVR Ecosystem and API Update
WebVR Ecosystem and API UpdateWebVR Ecosystem and API Update
WebVR Ecosystem and API Update
 
Foundations of the Immersive Web
Foundations of the Immersive WebFoundations of the Immersive Web
Foundations of the Immersive Web
 
The Immersive Web
The Immersive WebThe Immersive Web
The Immersive Web
 
Virtually Anyone
Virtually AnyoneVirtually Anyone
Virtually Anyone
 
React-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR DevelopmentReact-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR Development
 
WebGL: The Next Generation
WebGL:  The Next GenerationWebGL:  The Next Generation
WebGL: The Next Generation
 
Vrml, or There and Back Again
Vrml, or There and Back AgainVrml, or There and Back Again
Vrml, or There and Back Again
 
The Coming Distribution War
The Coming Distribution WarThe Coming Distribution War
The Coming Distribution War
 
Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015
 
VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015
 
An Introduction to Web VR January 2015
An Introduction to Web VR January 2015An Introduction to Web VR January 2015
An Introduction to Web VR January 2015
 
Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014
 
The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014
 
Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5
 
WebGL, WebVR and the Metaverse
WebGL, WebVR and the MetaverseWebGL, WebVR and the Metaverse
WebGL, WebVR and the Metaverse
 

Recently uploaded

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

WebGL and Web Site Performance

  • 1. WebGL and web site performance Tony Parisi September, 2014
  • 2. disclaimer I’m not a perf guy. but I am perf-curious. and I teach the world about WebGL. so I need to figure this out. why? WebGL devs need to understand high performance web site development the world is watching and there are lots of examples out there with bad perf practices we have an opportunity to add WebGL to the perf testing canon http://www.tonyparisi.com 9/17/2014
  • 3. about me http://www.meetup.com/WebGL-Developers-Meetup/ creds Co-creator, VRML and X3D work http://www.vizi.gl/ get GLAM http://www.glamjs.org/ https://github.com/tparisi/glam/ get VIZI https://github.com/tparisi/Vizi contact information tparisi@gmail.com skype: auradeluxe http://twitter.com/auradeluxe htt p://www.tonyparisi.com/ http://www.learningwebgl.com/ SF WebGL Meetup SF WebVR Meetup http://www.meetup.com/Web-VR/ book source code https://github.com/tparisi/WebGLBook https://github.com/tparisi/Programming3DApplications get the books! WebGL: Up and Running http://www.amazon.com/dp/144932357X Programming 3D Applications with HTML and WebGL http://www.amazon.com/Programming-Applications- HTML5-WebGL-Visualization/dp/1449362966 http://www.tonyparisi.com 9/17/2014
  • 4. performance savior… or scourge? SAVIOR… WebGL brings the power of the GPU to the web WebGL means no 3D plugins WebGL pioneered Typed Arrays: compact binary data for web applications WebGL has no DOM – no CSS or layout impact or SCOURGE? WebGL has no DOM – scripts required to see anything on the screen. lots of script code… LOTS. WebGL requires shaders – text programs that result in additional requests and client-side load/compile time WebGL pulls more content down the pipe WebGL apps tend toward full-screen… more front page content WebGL SUCKS… CPU (if you’re not careful) http://www.tonyparisi.com 9/17/2014
  • 5. the anatomy of a WebGL application 1. create a <canvas> element and obtain a WebGL drawing context var ctx= canvas.getContext(“webgl”); 2. load JavaScript setup code a. initialize viewport b. create buffers c. create matrices d. load texture maps 3. download and compile/link shaders 4. draw http://www.tonyparisi.com 9/17/2014
  • 6. first render no scripts… no pics. http://www.tonyparisi.com 9/17/2014
  • 7. shaders GLSL (Open GL Shader Language) – C-like language compiled onto the GPU and executed to position each vertex and paint each pixel. REQUIRED TO SEE ANYTHING ON THE SCREEN. var vertexShaderSource = " attribute vec3 vertexPos;n" + " attribute vec2 texCoord;n" + " uniform mat4 modelViewMatrix;n" + " uniform mat4 projectionMatrix;n" + " varying vec2 vTexCoord;n" + " void main(void) {n" + " // Return the transformed and projected vertex valuen" + " gl_Position = projectionMatrix * modelViewMatrix * n" + " vec4(vertexPos, 1.0);n" + " // Output the texture coordinate in vTexCoordn" + " vTexCoord = texCoord;n" + " }n"; var fragmentShaderSource = " precision mediump float;n" + " varying vec2 vTexCoord;n" + " uniform sampler2D uSampler;n" + " void main(void) {n" + " // Return the pixel color: always output whiten" + " gl_FragColor = texture2D(uSampler, vec2(vTexCoord.s, vTexCoord.t));n" + "}n"; the vertex shader transforms model-space positions into screen space the fragment shader outputs a color value for each pixel http://www.tonyparisi.com 9/17/2014
  • 8. more stuff to load (1) shader source code from Anton Gerdelan’s “Loading Shaders from Files with Ajax” http://antongerdelan.net/webgl/shadersandajax. html more files == more requests after download, this compile/link step consumes additional client side cycles http://www.tonyparisi.com 9/17/2014
  • 9. more stuff to load (2) JavaScript libraries programming WebGL to the metal not very productive; most people use an engine library Three.js – very popular 3D rendering engine 430k minified Tween.js – tweening (simple animation) 5k! nice more code from there – game engines, frameworks, app templates… it can get big. but we minify, compress, and defer loading. thus has it ever been. http://www.tonyparisi.com 9/17/2014
  • 10. more stuff to load (3) texture maps bitmaps applied to the surfaces of 3D objects image sprite-type techniques can help CSS sprites not supported directly one texture map can be used for several 3D objects – saves both download time and rendering time – but utility is limited to certain situations bigger savings will be in compressed, fast to load texture formats like DDS (currently in a WebGL extension) surface details of various parts, or even different objects, can be packed into a single image http://www.tonyparisi.com 9/17/2014
  • 11. more stuff to load (4) 3D models and scenes reminder: WebGL is an API. no file format. no DOM. current state of practice is to load JSON, or JSON + binary data in typed array (non-standard format) some apps use (shudder) XML 3D data description like COLLADA (“just server-side GZIP it, what’s the big deal…?”) new format: glTF http://www.gltf.gl/ a “JPEG for 3D” Khronos group initiative – pre-standard, experimental compact, efficient to load representation of 3D data GL native data types require no additional processing – stored as Typed Arrays also includes common 3D scene constructs: object hierarchy, cameras, lights, common material types, animation all data for a scene can be packed into a single file (or multiple, it’s totally flexible) can be streamed http://www.tonyparisi.com 9/17/2014
  • 12. what fold…? http://www.tonyparisi.com 9/17/2014 full-screen apps are making a comeback… more content on the front page… and nothing below the fold to optimize.
  • 13. what IS performance? (1) in games, fast run-time performance usually comes at the expense of large initial engine download pro game engine ports to WebGL are taking us back to the future Emscripten cross-compiled C++ to asm.js (low-level assembly-style JavaScript) – really fast and not leaky resulting JavaScript is HUGE – 10Mb+ http://www.tonyparisi.com 9/17/2014
  • 14. what IS performance? (2) what happens after first render? we could be creating a high-performance way to deliver perf hogs… WebGL apps can be CPU-suckers! lots of computation needs to be done on CPU JavaScript engines tend to be greedy… new Page Visibility API can help (but it doesn’t tell you when a window is occluded…) http://www.tonyparisi.com 9/17/2014 ! gah !
  • 15. some things to try inline shaders (defeats caching) pack shaders, unpack on client defer loading library code – start with small head end pack textures use DDS textures when the format becomes available (WebGL 2?) use procedural textures and geometry defer 3D content loading – load on navigate, visibility, combine with prediction use CSS3 3D transforms for front page/load screen – they are hardware-accelerated and can be rendered before scripts are loaded http://www.tonyparisi.com 9/17/2014
  • 16. WebGL sites: some perf tests WebGL showcase sites not optimized not sure end users care… these are showcases but View Source and copy-paste could spread bad practices pro sites showing mixed results but this could be similar to the distribution in non-WebGL sites… http://www.tonyparisi.com 9/17/2014
  • 17. making today’s perf tests WebGL-aware search DOM for canvas elements and WebGL patterns var c = document.createElement("canvas"); var gl1 = c.getContext("webgl"); // return WebGL context var ctx2d = c.getContext("2d"); // returns NULL. Canvas cannot have multiple context types. var gl2 = c.getContext("experimental-webgl"); // returns gl1. Browser treats experimental-webgl as an alias for webgl if succeeds then either (a) it’s already being used for WebGL or (b) false positive: uninitialized canvas look for inclusion of popularly used WebGL libraries like Three.js, Babylon.js, glMatrix… look for Ajaxing shader source files: .vs, .fs, .glsl look for Ajaxing popular model files: .stl, .obj, .dae, .gltf (soon) http://www.tonyparisi.com 9/17/2014
  • 18. the state of things WebGL presents new perf challenges scripts required to see anything on the screen more stuff to load – shaders, JS libraries, textures, models full-screen apps make it hard to use above-the-fold techniques game engines might trade load time for run-time speed… will users tolerate it? performance doesn’t end at first render; apps need to watch resources once loaded WebGL devs need to start thinking about site performance WebGL moving from demo to deployment, so we should start to see good perf techniques (we better!) most WebGL developers are game devs or visualization experts… great at frame rate but need to learn web site perf we should investigate adding WebGL checks to standard perf tests http://www.tonyparisi.com 9/17/2014