Performance
Runnable deck.gl example: Performance. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:deck.gl 性能对比
要点:同一份 26 万点数据在精简配置与高开销配置下渲染,实时显示帧率差异
依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>性能对比</title>
<style>
html,body{height:100%;margin:0;background:#0d1117}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
.bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
display:flex;gap:10px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:5px;cursor:pointer;
border:1px solid #303845;background:#1d2531;color:#c8d2e0}
.bar button:hover{background:#253040}
.bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
.bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
.fps{margin-left:auto;font-size:12px;color:#8b93a1}
.fps b{font-size:19px;color:#61d99b;font-variant-numeric:tabular-nums}
.fps b.low{color:#ff8c74}
#cv{flex:1 1 auto;min-height:0;width:100%}
</style>
</head>
<body>
<div class="bar">
<span>点数 <b id="n">—</b></span>
<span class="sep"></span>
<button data-mode="fast" class="on">精简配置</button>
<button data-mode="heavy">高开销配置</button>
<span class="sep"></span>
<span id="desc">像素半径 · 无描边 · 无拾取</span>
<span class="fps">帧率 <b id="fps">—</b> fps · 帧耗时 <b id="ft" style="font-size:12px">—</b> ms</span>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
'use strict';
if (typeof deck === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
var centers = [
[116.39, 39.90], [121.47, 31.23], [113.26, 23.12],
[104.06, 30.57], [114.05, 22.54], [108.94, 34.34]
];
var data = [];
for (var i = 0; i < 260000; i++) {
var c = centers[i % centers.length];
var r = Math.sqrt(Math.random()) * 1.0;
var a = Math.random() * Math.PI * 2;
data.push({
lng: c[0] + Math.cos(a) * r,
lat: c[1] + Math.sin(a) * r * 0.8,
v: Math.random()
});
}
document.getElementById('n').textContent = data.length.toLocaleString();
function baseProps(id) {
return {
id: id,
data: data,
getPosition: function (d) { return [d.lng, d.lat]; },
getFillColor: function (d) {
return [70 + d.v * 150, 150 - d.v * 40, 240 - d.v * 120, 175];
}
};
}
var fastLayer = new deck.ScatterplotLayer(Object.assign(baseProps('fast'), {
getRadius: 1.6,
radiusUnits: 'pixels',
radiusMinPixels: 1,
radiusMaxPixels: 3,
pickable: false
}));
function heavyLayers() {
var a = new deck.ScatterplotLayer(Object.assign(baseProps('heavy-a'), {
getRadius: 2.6,
radiusUnits: 'pixels',
radiusMinPixels: 1,
radiusMaxPixels: 6,
stroked: true,
getLineColor: [10, 16, 26, 120],
lineWidthUnits: 'pixels',
getLineWidth: 1,
antialiasing: true,
pickable: true
}));
var b = new deck.ScatterplotLayer(Object.assign(baseProps('heavy-b'), {
getRadius: 9,
radiusUnits: 'pixels',
radiusMaxPixels: 14,
getFillColor: [90, 170, 255, 16],
pickable: false
}));
var c = new deck.ScatterplotLayer(Object.assign(baseProps('heavy-c'), {
getRadius: 17,
radiusUnits: 'pixels',
radiusMaxPixels: 26,
getFillColor: [90, 170, 255, 7],
pickable: false
}));
return [a, b, c];
}
var layers = [fastLayer];
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 110.0,
latitude: 31.8,
zoom: 4.0,
pitch: 28,
bearing: 0,
maxPitch: 65
},
controller: true,
layers: layers,
useDevicePixels: true
});
var desc = document.getElementById('desc');
var buttons = document.querySelectorAll('[data-mode]');
for (var b = 0; b < buttons.length; b++) {
buttons[b].addEventListener('click', function (e) {
var mode = e.currentTarget.getAttribute('data-mode');
for (var k = 0; k < buttons.length; k++) {
buttons[k].classList.toggle('on', buttons[k] === e.currentTarget);
}
if (mode === 'fast') {
deckgl.setProps({ layers: [fastLayer], useDevicePixels: true, getTooltip: null });
desc.textContent = '像素半径 · 无描边 · 无拾取';
} else {
deckgl.setProps({
layers: heavyLayers(),
useDevicePixels: true,
getTooltip: function (info) {
if (!info.object) return null;
return info.object.lng.toFixed(3) + ', ' + info.object.lat.toFixed(3);
}
});
desc.textContent = '像素半径 · 描边 · 抗锯齿 · 拾取 · 三层叠加';
}
});
}
/* 帧率统计:只统计 requestAnimationFrame 的实际回调频率 */
var frames = 0;
var last = performance.now();
var fpsEl = document.getElementById('fps');
var ftEl = document.getElementById('ft');
function tick(now) {
frames++;
var span = now - last;
if (span >= 600) {
var fps = Math.round(frames * 1000 / span);
fpsEl.textContent = fps;
fpsEl.classList.toggle('low', fps < 30);
ftEl.textContent = fps > 0 ? (1000 / fps).toFixed(1) : '—';
frames = 0;
last = now;
}
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
window.__deck = deckgl;
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.