chutten / statuser

Blinky lights add-on for Firefox
3 stars 2 forks source link

Statuser causes main-thread jank itself #32

Open vdjeric opened 8 years ago

vdjeric commented 8 years ago

Statuser reported a few BHR hangs whose stack was entirely composed of an XRE_Main frame. I got curious and captured a profile -- if the BHR uptime timestamps are to be believed, the hang was caused by numGeckoThreadHangs() in Statuser itself.

Can this function be split up and made lighter?

chutten commented 8 years ago

Aside from the Services.telemetry.threadHangStats getter, the whole thing could be thrown into a Worker. However, the amount of processing we're doing is really low. If the runtime is that high, the number of hanging threads is high so find() is taking too long, the number of counts buckets is high so the foreach is taking too long, or some combination of both. Either way, it's the size of the input that's causing the slowdown, so it'll be expensive to send that much input to a worker.

IOW, I'm not sure that off-threading it would help.

Breaking it into pieces we could do. Throw a setTimeout(1) in the middle (after the refactor to Promises, no problem) and that might help.

We could refactor the counts.forEach to run backwards. We know we're looking for all contents of all buckets above a certain value, so we can early return going that way.

@Uberi , do you have any ideas to add?

avih commented 8 years ago

well.. we could assess this by measuring how long this call takes (from within the addon itself) and if it's more than, say, 2ms or so, do a console.log("numGeckoThreadHangs() took " + duration + " ms");

Uberi commented 8 years ago