deno icon indicating copy to clipboard operation
deno copied to clipboard

DevTools reports 100% CPU while doing nothing

Open alexgleason opened this issue 1 year ago • 7 comments

Version: Deno 1.39.0
Chromium: 120.0.6099.71

I created a simple reproduction script, gg.ts:

while (true) {
  await new Promise((resolve) => setTimeout(resolve, 1000));
}

Running it with deno run --inspect gg.ts and then viewing it in Chromium DevTools, the histogram at the top shows 100% CPU usage.

image

You can check my results in your DevTools here: CPU-20231217T142344.cpuprofile

This started happening recently, and I don't know why. The CPU itself is not close to 100% on any core when viewed with htop. The problem does not occur when profiling a normal webpage in the same browser, just when inspecting Deno.

alexgleason avatar Dec 17 '23 20:12 alexgleason

I believe this diagram doesn't show actual CPU usage, but show percentage of time the program spents in CPU. The (program) you see on your flamegraph is Devtools way of saying that it's running native code (the timer implementation) and the actual JavaScript code (all the function below eventLoopTick take 0ms - which is timer firing). So if anything I guess it's poor representation from Devtools perspective.

As a side note: timers are known to have poor performance: https://github.com/denoland/deno/issues/20356 and there's ongoing work to speed them up: https://github.com/denoland/deno/pull/20428

bartlomieju avatar Dec 17 '23 21:12 bartlomieju

I was able to dig up an old screenshot from some Deno profiling I did on November 20th:

Screenshot from 2023-11-20 19-21-32

The CPU chart at the top looks correct in this version.

I tried reverting my codebase to an old version (and downgrading to Deno 1.36), and I'm still having the problem in this issue. So that suggests to me something changed in Chromium rather than Deno, that makes Deno profiling a lot less useful.

alexgleason avatar Dec 17 '23 21:12 alexgleason

I tried reverting my codebase to an old version (and downgrading to Deno 1.36), and I'm still having the problem in this issue. So that suggests to me something changed in Chromium rather than Deno, that makes Deno profiling a lot less useful.

I agree, IIRC a couple months back (program) was colored in gray and didn't count towards "Scripting" category (which it does now).

Chrome DevTools devs asked for feedback on this panel, which appears to just been closed: https://github.com/ChromeDevTools/rfcs/discussions/2 I suggest to open an issue with them. I'll be happy to coordinate on that.

bartlomieju avatar Dec 17 '23 21:12 bartlomieju

Thanks @bartlomieju, opened an issue here: https://bugs.chromium.org/p/chromium/issues/detail?id=1512463

alexgleason avatar Dec 17 '23 22:12 alexgleason

See https://github.com/denoland/deno/issues/24877#issuecomment-2276989796 for a workaround/fix that is just as applicable to this issue.

june07 avatar Aug 09 '24 01:08 june07