opcache-status icon indicating copy to clipboard operation
opcache-status copied to clipboard

High cpu usage on tab switch

Open Gamesh opened this issue 10 years ago • 16 comments

Firefox console displays warning: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create

...{Yi=r}var Ii=[].proto?function(t,n){t.proto=n}:function(t,n){for(var e i... in file d3.v3.min.js.

and indead when you click on a tab cpu spikes to 10-16%, just to switch a tab. on a Quad core i7 CPU. I don't think that much cpu is needed just to hide and show a div, it should be snappy and fast.

Gamesh avatar Oct 30 '14 12:10 Gamesh

Yes, this is a problem. It seems it is an abandoned project.

szepeviktor avatar Oct 30 '14 12:10 szepeviktor

JS and that piece of data could be restricted to that tab. E.g. loading it later by AJAX. So looking at other tabs would be smooth.

szepeviktor avatar Jan 21 '15 09:01 szepeviktor

@cviebrock seems like something for you

rlerdorf avatar Jan 21 '15 09:01 rlerdorf

@szepeviktor i don't think AJAX will solve anything. as the data is already loaded on the page and it loads very fast. The main problem here in my opinion is in javascript that switches the tab it is causing the slow down, not the data itself.

Maybe just stick with $.show() $.hide() and don't do any transitions:

if (!hidden[row]) {
d3.selectAll(row).transition().style('display', 'none');
hidden[row] = true;
d3.select(head).transition().style('color', '#ccc');
} else {
d3.selectAll(row).transition().style('display');
hidden[row] = false;
d3.select(head).transition().style('color', '#000');
}

and if you need odd/even row coloring do it with CSS3

Gamesh avatar Jan 21 '15 11:01 Gamesh

I'll take a look ... it's been a while. ;)

cviebrock avatar Jan 21 '15 21:01 cviebrock

glad to know that project is up and running again at least :)

Gamesh avatar Jan 22 '15 06:01 Gamesh

Tried updating jQuery and d3js to more recent versions, and I still get that ~~error~~ warning. A quick google search turns up this: https://github.com/mbostock/d3/issues/1805

So, I'd say this is an issue with d3js, perhaps only within Firefox. I don't see those JS warnings in Chrome's console, and the CPU doesn't seem to spike as much as it does in FF.

I did convert the hiding/showing of tabs to use Jquery instead of d3. Do you want to try my branch at https://github.com/cviebrock/opcache-status/tree/update-d3js and see if that helps?

cviebrock avatar Jan 23 '15 06:01 cviebrock

tried it and it works great and fast. but d3 still produces an error when clicking through tabs:

TypeError: dataset[this.value] is undefined
http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js
Line 1

TypeError: dataset[this.value] is undefined
http://myserverutils/opcache.php
Line 4125

maybe we should ditch d3 entirely? it looks somewhat unstable

Gamesh avatar Jan 23 '15 06:01 Gamesh

d3 has been around for quite some time and is used in lots of places, so I don't think it's necessarily unstable. And ditching it would mean no pretty circular graph or partition visualization.

That particular error comes from our code:

https://github.com/cviebrock/opcache-status/blob/update-d3js/opcache.php#L605

I'd have to sit down for a few hours and figure out what's actually going on here. I'm sure it could be cleaned up.

cviebrock avatar Jan 23 '15 15:01 cviebrock

It's just seems that D3 does pretty much the same thing that jquery does, but also includes ability to draw these graphs. My thought was to use something more lightweight just for graphs and stick with jquery for everything else

Gamesh avatar Jan 23 '15 17:01 Gamesh

If you can find something that does this, that'd be great. The circular graphs I think would be easy to do in other JS charting libraries, but I'm not sure anyone else does the partitioning stuff.

cviebrock avatar Jan 23 '15 17:01 cviebrock

For partitioning these look very similar, take a look Google Treemaps https://google-developers.appspot.com/chart/interactive/docs/gallery/treemap

ZingChart treemap: http://www.zingchart.com/docs/chart-types/treemap/

Kendo UI treemap http://demos.telerik.com/kendo-ui/treemap/index

Gamesh avatar Jan 23 '15 18:01 Gamesh

Neither Zing nor Kendo are viable since they are commercial. There are tons of them out there though. See: http://socialcompare.com/en/comparison/javascript-graphs-and-charts-libraries You can ignore all the non-opensource ones.

rlerdorf avatar Jan 23 '15 18:01 rlerdorf

what about just using google charts api?

Gamesh avatar Jan 25 '15 15:01 Gamesh

+1 for Google Charts, they are very nice to work. See: https://developers.google.com/chart/interactive/docs/gallery

jamesrwhite avatar Jan 25 '15 18:01 jamesrwhite

highcharts is also a good alternative. http://www.highcharts.com/

ningt avatar Jun 19 '15 10:06 ningt