Vladimir Agafonkin
High Performance
Data Visualizations
April 2013
Slide 2
Slide 2 text
rain.in.ua
Slide 3
Slide 3 text
agafonkin.com
/mourner
Slide 4
Slide 4 text
No content
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
data visualization
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
No content
Slide 10
Slide 10 text
No content
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
not static anymore
Slide 14
Slide 14 text
responding to user actions
clicking, hovering, scrolling,
touch gestures, etc.
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
No content
Slide 17
Slide 17 text
No content
Slide 18
Slide 18 text
navigating through data
Slide 19
Slide 19 text
filtering
Slide 20
Slide 20 text
demand for real-time
interactivity is increasing
Slide 21
Slide 21 text
responsibility for processing data
is shifting from the server
to the browser
Slide 22
Slide 22 text
lots of data
+
lots of rendering
=
big performance problem
Slide 23
Slide 23 text
pure JS
fast
rendering, DOM
slow
Slide 24
Slide 24 text
rule #1
the less stuff we render
the better
Slide 25
Slide 25 text
data
processing
rendering
Slide 26
Slide 26 text
data processing rendering
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
data reduction
Slide 29
Slide 29 text
search
Slide 30
Slide 30 text
loading data
once
searching data
lots of times
Slide 31
Slide 31 text
search index
Slide 32
Slide 32 text
grid
Slide 33
Slide 33 text
tree data structures
•binary heap
•binary search tree
•range tree
•k-d tree
•quadtree
•R-tree
Slide 34
Slide 34 text
points – quadtree
Slide 35
Slide 35 text
rectangles – R-tree
Slide 36
Slide 36 text
var tree = new RTree();
tree.insert(
{x: 5, y: 10, w: 10, h: 15}, obj);
...
tree.search(
{x: 7, y: 7, w: 5, h: 5});
github.com/imbcmdth/RTree
Slide 37
Slide 37 text
kothic.org/js
Slide 38
Slide 38 text
collision detection
Slide 39
Slide 39 text
Crossfilter (many dimensions)
Slide 40
Slide 40 text
geometric clipping
Slide 41
Slide 41 text
polyline clipping
Cohen-Sutherland algorithm
Slide 42
Slide 42 text
polygon clipping
Sutherland-Hodgeman algorithm
Slide 43
Slide 43 text
polyline simplification
Slide 44
Slide 44 text
distance-based simplification
Slide 45
Slide 45 text
Douglas-Peucker
simplification
Slide 46
Slide 46 text
mourner.github.com/simplify-js
Slide 47
Slide 47 text
clustering
grouping objects which are
close to each other
Slide 48
Slide 48 text
No content
Slide 49
Slide 49 text
No content
Slide 50
Slide 50 text
hierarchical clustering
once for all zoom
levels
Slide 51
Slide 51 text
data loading and
processing
Slide 52
Slide 52 text
UI JS
browser freezes
on heavy calculations
UI
Slide 53
Slide 53 text
Web Workers
Slide 54
Slide 54 text
...
worker.postMessage(HUGE_DATA_ARRAY);
...
loading and sending to Worker
Slide 55
Slide 55 text
UI
Worker JS
browser freezes on data loading
and sending
data
loading UI
Slide 56
Slide 56 text
importScripts('data.js');
...
onmessage = function (e) {
var result =
searchData(e.data.query);
postMessage(result);
}
Loading in Worker
Slide 57
Slide 57 text
UI
Worker JS
browser freezes when receiving
data from Worker
data
loading
UI
UI
Slide 58
Slide 58 text
var array = new Float16Array(len);
...
var buffer = array.buffer;
postMessage(buffer, [buffer]);
// buffer stops being available
transferable objects
(Chrome, Firefox)
Slide 59
Slide 59 text
UI
Worker JS
browser doesn't freeze,
data is sent as ArrayBuffer
data
loading
UI
UI
Slide 60
Slide 60 text
function addNumbers(a, b) {
'use asm';
a = a | 0; // int
b = +b; // double
return +(a + b); // double
}
bright future — asm.js
Slide 61
Slide 61 text
bright future — asm.js
•useful for computational
bottlenecks
•FF Nightly; V8 on the way
•backwards compatibility!
Slide 62
Slide 62 text
rendering backends
SVG, Canvas, WebGL
Slide 63
Slide 63 text
SVG
•fast native events for
interactivity
•easy to update separate
objects
•slows down the browser (with
a large number of objects)
Slide 64
Slide 64 text
Canvas
•doesn't affect browser
performance after rendering
•you can draw something once
and copy
•pixel data can be manipulated
or generated in a Worker
Slide 65
Slide 65 text
Canvas
•expensive to redraw with
each update
•hard to implement
interactivity
Slide 66
Slide 66 text
WebGL
•main way to visualize in 3D
•very fast in 2D if you need to draw lots
of sprites
•performance gain vs Canvas-2D is
questionable in other cases
•much more difficult to use; limitations
•no support in iOS and IE9-10
Slide 67
Slide 67 text
low number of objects:
use SVG
lots of stuff to draw:
use Canvas