viz: speed up profiler first render (#15632)

* viz: speed up profiler first render

* better comment
This commit is contained in:
qazal
2026-04-07 17:07:09 +03:00
committed by GitHub
parent d3de63d998
commit d29f0ef721

View File

@@ -408,8 +408,8 @@ async function renderProfiler(path, opts) {
canvas.addEventListener("wheel", e => (e.stopPropagation(), e.preventDefault()), { passive:false });
const ctx = canvas.getContext("2d");
const canvasTop = rect(canvas).top;
// color by key (name/device)
const colorMap = new Map();
// map event name to shape and label colors
const colorMap = new Map(), coloredNames = new Map();
// map shapes by event key
const shapeMap = new Map();
const heightScale = d3.scaleLinear().domain([0, tracePeak]).range([4,maxheight=100]);
@@ -448,11 +448,14 @@ async function renderProfiler(path, opts) {
colorMap.set(colorKey, d3.rgb(color));
}
const fillColor = colorMap.get(colorKey).brighter(0.3*depth).toString();
const label = parseColors(e.name).flatMap(({ color, st }) => {
const parts = [];
for (let i=0; i<st.length; i+=4) { const part = st.slice(i, i+4); parts.push({ color, st:part, width:ctx.measureText(part).width }); }
return parts;
});
let label = coloredNames.get(e.name);
if (label == null) {
label = parseColors(e.name).flatMap(({ color, st }) => {
const parts = [];
for (let i=0; i<st.length; i+=4) { const part = st.slice(i, i+4); parts.push({ color, st:part, width:ctx.measureText(part).width }); }
return parts;
}); coloredNames.set(e.name, label);
}
let shapeRef = e.ref;
if (shapeRef != null) { ref = {ctx:e.ref, step:0}; shapeRef = ref; }
else if (ref != null) {