SlideShare a Scribd company logo
1 of 25
Download to read offline
Alternative rendering
Canvas, WebGL, SVG
Why not DOM ?
It is slow since is a quite complex model
Canvas
Simple and sometimes fast
Display image: DOM vs Canvas
DOM Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
● Append IMG tag
Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
● Append IMG tag
● Calc. styles
Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
● Append IMG tag
● Calc. styles
● Calc. position
Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
● Append IMG tag
● Calc. styles
● Calc. position
● Display image
Canvas
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
● Append IMG tag
● Calc. styles
● Calc. position
● Display image
Canvas
● Load file
Display image: DOM vs Canvas
DOM
● Create IMG tag
● Load file
● Append IMG tag
● Calc. styles
● Calc. position
● Display image
Canvas
● Load file
● ctx.drawImage
DOM is hardly predictable
< 100 msec
100-300 msec
300 - 1000 msec
1+ sec
10+ sec
Instant response
Small delay
System works
Switching task
Cancelling operation
When to use?
1. A lot of animated objects
2. Dynamicly changing shapes
3. Need highly consistent browser behaviour
4. Solution should be easy to maintain and
widely compatible
Tricks
1. Smaller means faster (width, height)
2. Rounded coordinates for drawing
3. Draw from another canvas, not image
4. Use RAF and decrease framerate if needed
(skip some frames)
5. Use few canvases if have content partially
changing
WebGL
Fast, amazing and hard to use
WebGL: Good parts
1. You may utilize GPU in the best way
2. After you sent shaders and buffers to GPU
you do not use JS anymore and it makes
rendering incredibly fast
3. WebGL calls are inspectable with vast see of
optimizations and workarounds possible
When to use?
1. A lot of animated objects
2. Need highest performance possible
3. Have high budget and modern hardware
Tricks
1. Debug WebGL calls with WebGL inspector
2. Check your drivers, are they bottleneck?
3. Use engines (Pixi, Cocos2d, Three)
4. Move to declarative engine (HTML-GL)
WebGL: Bad parts
DOM
<img src=”back.png”>
WebGL (three.js)
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var camera = new THREE.PerspectiveCamera(45,
window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 500;
var scene = new THREE.Scene();
var material = new THREE.MeshLambertMaterial({
map:
THREE.ImageUtils.loadTexture('http://www.html5canvastutorials.co
m/demos/assets/crate.jpg')});
var plain = new THREE.Mesh(new THREE.Plain(200, 200),
material);
scene.add(plain);
HTML-GL?
DOM
<img src=”back.png”>
HTML-GL
<html-gl>
<img src=”back.png”>
</html-gl>
htmlgl.com
SVG
No speed improvement,
but some effects
When to use?
1. Need vector shapes animated and scalable
interface elements
2. Do not care about FPS too much
3. Have browsers supporting SVG
Trick
SVG layer is not hardware accelerated and
causes repaints when something is moved, but
you may wrap it with GPU accelerated element
and apply transformations on that element
instead of SVG

More Related Content

More from Ontico

More from Ontico (20)

Новые технологии репликации данных в PostgreSQL / Александр Алексеев (Postgre...
Новые технологии репликации данных в PostgreSQL / Александр Алексеев (Postgre...Новые технологии репликации данных в PostgreSQL / Александр Алексеев (Postgre...
Новые технологии репликации данных в PostgreSQL / Александр Алексеев (Postgre...
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
 
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
 
Опыт разработки модуля межсетевого экранирования для MySQL / Олег Брославский...
Опыт разработки модуля межсетевого экранирования для MySQL / Олег Брославский...Опыт разработки модуля межсетевого экранирования для MySQL / Олег Брославский...
Опыт разработки модуля межсетевого экранирования для MySQL / Олег Брославский...
 
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
 
MySQL Replication — Advanced Features / Петр Зайцев (Percona)
MySQL Replication — Advanced Features / Петр Зайцев (Percona)MySQL Replication — Advanced Features / Петр Зайцев (Percona)
MySQL Replication — Advanced Features / Петр Зайцев (Percona)
 
Внутренний open-source. Как разрабатывать мобильное приложение большим количе...
Внутренний open-source. Как разрабатывать мобильное приложение большим количе...Внутренний open-source. Как разрабатывать мобильное приложение большим количе...
Внутренний open-source. Как разрабатывать мобильное приложение большим количе...
 
Подробно о том, как Causal Consistency реализовано в MongoDB / Михаил Тюленев...
Подробно о том, как Causal Consistency реализовано в MongoDB / Михаил Тюленев...Подробно о том, как Causal Consistency реализовано в MongoDB / Михаил Тюленев...
Подробно о том, как Causal Consistency реализовано в MongoDB / Михаил Тюленев...
 
Балансировка на скорости проводов. Без ASIC, без ограничений. Решения NFWare ...
Балансировка на скорости проводов. Без ASIC, без ограничений. Решения NFWare ...Балансировка на скорости проводов. Без ASIC, без ограничений. Решения NFWare ...
Балансировка на скорости проводов. Без ASIC, без ограничений. Решения NFWare ...
 
Перехват трафика — мифы и реальность / Евгений Усков (Qrator Labs)
Перехват трафика — мифы и реальность / Евгений Усков (Qrator Labs)Перехват трафика — мифы и реальность / Евгений Усков (Qrator Labs)
Перехват трафика — мифы и реальность / Евгений Усков (Qrator Labs)
 
И тогда наверняка вдруг запляшут облака! / Алексей Сушков (ПЕТЕР-СЕРВИС)
И тогда наверняка вдруг запляшут облака! / Алексей Сушков (ПЕТЕР-СЕРВИС)И тогда наверняка вдруг запляшут облака! / Алексей Сушков (ПЕТЕР-СЕРВИС)
И тогда наверняка вдруг запляшут облака! / Алексей Сушков (ПЕТЕР-СЕРВИС)
 
Как мы заставили Druid работать в Одноклассниках / Юрий Невиницин (OK.RU)
Как мы заставили Druid работать в Одноклассниках / Юрий Невиницин (OK.RU)Как мы заставили Druid работать в Одноклассниках / Юрий Невиницин (OK.RU)
Как мы заставили Druid работать в Одноклассниках / Юрий Невиницин (OK.RU)
 
Разгоняем ASP.NET Core / Илья Вербицкий (WebStoating s.r.o.)
Разгоняем ASP.NET Core / Илья Вербицкий (WebStoating s.r.o.)Разгоняем ASP.NET Core / Илья Вербицкий (WebStoating s.r.o.)
Разгоняем ASP.NET Core / Илья Вербицкий (WebStoating s.r.o.)
 
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
 
Apache Ignite Persistence: зачем Persistence для In-Memory, и как он работает...
Apache Ignite Persistence: зачем Persistence для In-Memory, и как он работает...Apache Ignite Persistence: зачем Persistence для In-Memory, и как он работает...
Apache Ignite Persistence: зачем Persistence для In-Memory, и как он работает...
 
Механизмы мониторинга баз данных: взгляд изнутри / Дмитрий Еманов (Firebird P...
Механизмы мониторинга баз данных: взгляд изнутри / Дмитрий Еманов (Firebird P...Механизмы мониторинга баз данных: взгляд изнутри / Дмитрий Еманов (Firebird P...
Механизмы мониторинга баз данных: взгляд изнутри / Дмитрий Еманов (Firebird P...
 
Как мы учились чинить самолеты в воздухе / Евгений Коломеец (Virtuozzo)
Как мы учились чинить самолеты в воздухе / Евгений Коломеец (Virtuozzo)Как мы учились чинить самолеты в воздухе / Евгений Коломеец (Virtuozzo)
Как мы учились чинить самолеты в воздухе / Евгений Коломеец (Virtuozzo)
 
Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)
Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)
Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)
 
Как построить кластер для расчета сотен тысяч high-CPU/high-MEM-задач и не ра...
Как построить кластер для расчета сотен тысяч high-CPU/high-MEM-задач и не ра...Как построить кластер для расчета сотен тысяч high-CPU/high-MEM-задач и не ра...
Как построить кластер для расчета сотен тысяч high-CPU/high-MEM-задач и не ра...
 
Отказоустойчивая архитектура фронтальной системы банка / Роман Шеховцов, Алек...
Отказоустойчивая архитектура фронтальной системы банка / Роман Шеховцов, Алек...Отказоустойчивая архитектура фронтальной системы банка / Роман Шеховцов, Алек...
Отказоустойчивая архитектура фронтальной системы банка / Роман Шеховцов, Алек...
 

Recently uploaded

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 

Альтернативные технологии рендеринга контента: SVG, Canvas, WebGL / Денис Радин (Liberty Global)

  • 2. Why not DOM ? It is slow since is a quite complex model
  • 4. Display image: DOM vs Canvas DOM Canvas
  • 5. Display image: DOM vs Canvas DOM ● Create IMG tag Canvas
  • 6. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file Canvas
  • 7. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file ● Append IMG tag Canvas
  • 8. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file ● Append IMG tag ● Calc. styles Canvas
  • 9. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file ● Append IMG tag ● Calc. styles ● Calc. position Canvas
  • 10. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file ● Append IMG tag ● Calc. styles ● Calc. position ● Display image Canvas
  • 11. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file ● Append IMG tag ● Calc. styles ● Calc. position ● Display image Canvas ● Load file
  • 12. Display image: DOM vs Canvas DOM ● Create IMG tag ● Load file ● Append IMG tag ● Calc. styles ● Calc. position ● Display image Canvas ● Load file ● ctx.drawImage
  • 13. DOM is hardly predictable < 100 msec 100-300 msec 300 - 1000 msec 1+ sec 10+ sec Instant response Small delay System works Switching task Cancelling operation
  • 14. When to use? 1. A lot of animated objects 2. Dynamicly changing shapes 3. Need highly consistent browser behaviour 4. Solution should be easy to maintain and widely compatible
  • 15. Tricks 1. Smaller means faster (width, height) 2. Rounded coordinates for drawing 3. Draw from another canvas, not image 4. Use RAF and decrease framerate if needed (skip some frames) 5. Use few canvases if have content partially changing
  • 16. WebGL Fast, amazing and hard to use
  • 17. WebGL: Good parts 1. You may utilize GPU in the best way 2. After you sent shaders and buffers to GPU you do not use JS anymore and it makes rendering incredibly fast 3. WebGL calls are inspectable with vast see of optimizations and workarounds possible
  • 18. When to use? 1. A lot of animated objects 2. Need highest performance possible 3. Have high budget and modern hardware
  • 19. Tricks 1. Debug WebGL calls with WebGL inspector 2. Check your drivers, are they bottleneck? 3. Use engines (Pixi, Cocos2d, Three) 4. Move to declarative engine (HTML-GL)
  • 20. WebGL: Bad parts DOM <img src=”back.png”> WebGL (three.js) var renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000); camera.position.z = 500; var scene = new THREE.Scene(); var material = new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture('http://www.html5canvastutorials.co m/demos/assets/crate.jpg')}); var plain = new THREE.Mesh(new THREE.Plain(200, 200), material); scene.add(plain);
  • 24. When to use? 1. Need vector shapes animated and scalable interface elements 2. Do not care about FPS too much 3. Have browsers supporting SVG
  • 25. Trick SVG layer is not hardware accelerated and causes repaints when something is moved, but you may wrap it with GPU accelerated element and apply transformations on that element instead of SVG