Skip to content

Commit

Permalink
Merge pull request brendangregg#265 from hassec/js_perf_fixes
Browse files Browse the repository at this point in the history
fix: javascript performance issues (slow zoom() unzoom())
  • Loading branch information
brendangregg authored Sep 18, 2022
2 parents b0bef43 + f435e4c commit 36c7729
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions flamegraph.pl
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,15 @@ sub flow {
if (e.ctrlKey === false) return;
e.preventDefault();
}
if (target.classList.contains("parent")) unzoom();
if (target.classList.contains("parent")) unzoom(true);
zoom(target);
if (!document.querySelector('.parent')) {
clearzoom();
// we have basically done a clearzoom so clear the url
var params = get_params();
if (params.x) delete params.x;
if (params.y) delete params.y;
history.replaceState(null, null, parse_params(params));
unzoombtn.classList.add("hide");
return;
}
Expand Down Expand Up @@ -890,11 +895,15 @@ sub flow {
}
t.textContent = txt;
// Fit in full text width
if (/^ *\$/.test(txt) || t.getSubStringLength(0, txt.length) < w)
var sl = t.getSubStringLength(0, txt.length);
// check if only whitespace or if we can fit the entire string into width w
if (/^ *\$/.test(txt) || sl < w)
return;
for (var x = txt.length - 2; x > 0; x--) {
// this isn't perfect, but gives a good starting point
// and avoids calling getSubStringLength too often
var start = Math.floor((w/sl) * txt.length);
for (var x = start; x > 0; x = x-2) {
if (t.getSubStringLength(0, x + 2) <= w) {
t.textContent = txt.substring(0, x) + "..";
return;
Expand Down Expand Up @@ -1000,14 +1009,14 @@ sub flow {
}
search();
}
function unzoom() {
function unzoom(dont_update_text) {
unzoombtn.classList.add("hide");
var el = document.getElementById("frames").children;
for(var i = 0; i < el.length; i++) {
el[i].classList.remove("parent");
el[i].classList.remove("hide");
zoom_reset(el[i]);
update_text(el[i]);
if(!dont_update_text) update_text(el[i]);
}
search();
}
Expand Down

0 comments on commit 36c7729

Please sign in to comment.