Closed Bug 1684139 Opened 3 years ago Closed 3 years ago

High CPU use on sports.williamhill.com due to unclamped setInterval(f, 0) in worker

Categories

(Core :: DOM: Workers, defect, P2)

defect

Tracking

()

VERIFIED FIXED
88 Branch
Performance Impact medium
Tracking Status
firefox88 --- verified

People

(Reporter: yoasif, Assigned: edenchuang)

References

(Blocks 2 open bugs, )

Details

(Keywords: perf:resource-use, power)

Attachments

(5 files)

From: https://www.reddit.com/r/firefox/comments/ki70v8/firefox_8401_see_all_new_features_updates_and/ggterzu/

Basic information

Steps to Reproduce:

Since 84 and 84.0.1 My CPU usage goes to 25% with one page open and if I open 3 tabs nearly 100% but have only seen this behaviour on One Site https://sports.williamhill.com/betting/en-gb/horse-racing/meetings/all/today

Have just tried this WilliamHill website on my Laptop and it's using the same extreme CPU at 100% with 3 Tabs from that site open. So not my Desktop then. I'm an avid gambler and like to have a one tab perhorse race meeting.

Expected Results:

Been using it for years without problems. So weird it just seems to be this site.

Actual Results:

I can have 20 other tabs open and only +/- 7% CPU usage.

But open one tab of WHill and it jumps to 27%-33 2 tabs 75ish and 3 tabs 100% and my desktop is like a furnace


More information

The user is in the UK and the site is geographically restricted to this region.

Profile URL: https://share.firefox.dev/37I9nyw

Basic systems configuration:

OS version: Windows 10

GPU model: AMD Radeon Pro WX 2100

Number of cores: AMD FX -8350 Eight-Core

Amount of memory (RAM): 16gb RAM

Thanks so much for your help.

Attached file about:support
Has STR: --- → yes
Keywords: regression

:yoasif, could you try to find a regression range using for example mozregression?

QA Whiteboard: [qa-regression-triage]

I tried to reproduce this issue using NordVPN to access https://sports.williamhill.com/ on a Windows 10 machine with AMD processor (AMD FX-8320) and AMD Radeon HD5450, I don't get more then 20-30% CPU usage even when having more then 10 tabs with heavy content in them.

I can see the same high CPU load with Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:86.0) Gecko/20100101 Firefox/86.0 ID:20210103213448. It's even constantly at 140% when I allow Javascript from williamhill.com, and whcdn.net. Disallowing Javascript from the latter domain drops the CPU load to just 20%. So whatever is loaded and run via whcdn.net is causing the high CPU load.

I wouldn't consider this a regression given that it goes all back to at least Firefox 45.0ESR, which is the oldest release that I have tested.

Here my recorded profile: https://share.firefox.dev/3opiwSg

At the beginning I had all the Javascript disabled (NoScript), and then I temporarily enabled it, which caused a reload of the page. Starting by around 15s the high CPU load can be seen.

Blocks: power-usage
QA Whiteboard: [qa-regression-triage]

Asif, can you please re-check if that really starts with Firefox 84 for you? Thanks.

Flags: needinfo?(yoasif)

Closing as resolved incomplete until we have the information requested in comment #5. Please reopen this bug when you have the information.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → INCOMPLETE

I can reproduce the high CPU load, so there is no reason to close this bug. The only question is if this is a regression or not.

Here another profile with CPU utilization enabled: https://share.firefox.dev/36ks1eL

Interesting is that the high CPU load of the web content process doesn't change when the tab is moved into the background. There is always a load of ~120%. Using about:processes I can see that 70% is used on the DOM Worker thread, and 55% on the Timer thread.

As such here a new profile with profiling of both threads enabled: https://share.firefox.dev/3t9G6pe

Status: RESOLVED → REOPENED
Component: Performance → DOM: Workers
Flags: needinfo?(yoasif)
Resolution: INCOMPLETE → ---

Yeah, I can reproduce on linux too. Something going wrong with timers in a worker.

Whiteboard: [qf]

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+1] from comment #7)

As such here a new profile with profiling of both threads enabled: https://share.firefox.dev/3t9G6pe

There is some ping-pong between timer and worker thread, but most of the time spent in both threads seem to be inside the system level __psynch_cvwait ? That should not add much real CPU load (though it shows as such in the profile)?

(In reply to Jens Stutte [:jstutte] from comment #9)

There is some ping-pong between timer and worker thread, but most of the time spent in both threads seem to be inside the system level __psynch_cvwait ? That should not add much real CPU load (though it shows as such in the profile)?

I don't know. Stephen do you have an idea why the CPU load is that high here?

Flags: needinfo?(spohl.mozilla.bugs)

(In reply to Jens Stutte [:jstutte] from comment #9)

There is some ping-pong between timer and worker thread, but most of the time spent in both threads seem to be inside the system level __psynch_cvwait ? That should not add much real CPU load (though it shows as such in the profile)?

I don't know. Stephen do you have an idea why the CPU load is that high here?

Status: REOPENED → NEW

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+1] from comment #11)

(In reply to Jens Stutte [:jstutte] from comment #9)

There is some ping-pong between timer and worker thread, but most of the time spent in both threads seem to be inside the system level __psynch_cvwait ? That should not add much real CPU load (though it shows as such in the profile)?

I don't know. Stephen do you have an idea why the CPU load is that high here?

No, I don't know either. Maybe Markus has seen something like this before?

Flags: needinfo?(spohl.mozilla.bugs) → needinfo?(mstange.moz)

It means that it's called many many times.

Flags: needinfo?(mstange.moz)
Severity: -- → S3
Priority: -- → P2

The page is using setInterval in the worker. Chrome clamps it to 4ms, we don't.

Summary: High CPU use since 84 in sports.williamhill.com → High CPU use since 84 in sports.williamhill.com due to unclamped setInterval(f, 0) in worker
Attached file testcase

Clamping should happen:
"If nesting level is greater than 5, and timeout is less than 4, then set timeout to 4."
https://html.spec.whatwg.org/#timer-initialisation-steps

This feels like a bug in Chrome.

Aha, I was wrong.
there is "for the repeating timers created by setInterval()."
to check nested level.
We're missing that.

Hi Eden, can you please check how hard it would be to implement that clamping? I hope it is just one spot in the code, but...

Flags: needinfo?(echuang)
Assignee: nobody → echuang
Flags: needinfo?(echuang)

We didn't find (yet) that this is a regression. Eden, if you notice something different and it's indeed a regression around the to modify code we might have to uplift the fix to 86 beta. For now removing the misleading part from the summary.

Summary: High CPU use since 84 in sports.williamhill.com due to unclamped setInterval(f, 0) in worker → High CPU use on sports.williamhill.com due to unclamped setInterval(f, 0) in worker
Version: Firefox 84 → unspecified

I guess the bug happens from an ancient version since the nesting timer level seems never to be implemented for workers. I test Firefox 74, the bug also happens.
We don't have a regression because there is no test case for it, and it is a little bit hard to test setTimeout/timeInterval automatically.
So I am not sure should uplift this fix to 86 beta.

Whiteboard: [qf] → [qf:p2:resource]
Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3a13a7b09c92
Implement timer nesting level for workers r=dom-worker-reviewers,asuth
https://hg.mozilla.org/integration/autoland/rev/209b51d63e6e
Adding mozilla specific wpt for timer nesting level in workers r=dom-worker-reviewers,asuth
Backout by abutkovits@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6b2b5822961a
Backed out 2 changesets for causing failures at test_subprocess.js. CLOSED TREE

rerun the test case on try, but got green.

Flags: needinfo?(echuang)

I am not sure if the fail is related to the patches.
I met the same test fail on my local without the patches.

Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/23e0fa285d90
Implement timer nesting level for workers r=dom-worker-reviewers,asuth
https://hg.mozilla.org/integration/autoland/rev/52cfd9509136
Adding mozilla specific wpt for timer nesting level in workers r=dom-worker-reviewers,asuth

Backed out 2 changesets (Bug 1684139) for causing xpcshell failures in test_subprocess.js

Backout link: https://hg.mozilla.org/integration/autoland/rev/50e993a9a4a972df1c5fdeca2167d01fb0d92d4f

Push with failures
Failure log

Flags: needinfo?(echuang)
Flags: needinfo?(echuang)

Hi, I originally posted this problem to/reddit and Asif Youssiff kindly added this bug here for me.

I have been reading the above but all/most of it is WAY Over my head.

As of 85.0.2 this problem persists on One website only. WilliamHill.com

With one tab open my CPU goes to 25-30% till if I open 3 tabs goes to 100% and my PC starts to feel like a furnace
I have the exact same result on my laptop.

Is there perhaps someone who has found out a fix for this ? Something I could alter in About:config ?

It's really frustrating and been having this problem since a week before Christmas.
Many thanks for taking the time to read, Tom

(In reply to Tom Mc from comment #32)

Is there perhaps someone who has found out a fix for this ? Something I could alter in About:config ?

Hi Tom, thanks for checking in here. There is a fix on the way that will help to mitigate this problem of some websites. It just needs to go through our quality assurance chain. Once you see this bug closed, you can install the nightly version of Firefox or just wait for the 88 release.

PS Just updated to 86.0 and No Change !

pulling my hair out

Ah, just saw the comment from Jens Stutte. Thanks for taking the time to let me know.

88 release . Can't wait till this happens. Is there a ballpark time that this will take effect, perhaps ?

Thanks for replying, Jens Stutte

Tom, you could try the following build, which was produced in our CI while the patch was landed for a while but then backed out:
https://archive.mozilla.org/pub/firefox/nightly/2021/02/2021-02-25-21-55-04-mozilla-central/firefox-88.0a1.en-US.win64.zip

Just extract the zip archive and run firefox.exe with your profile. If you could let us know how it works that would be great. Thanks!

Flags: needinfo?(tommckey)

Tom, you could try the following build, which was produced in our CI while the patch was landed for a while but then backed out:
https://archive.mozilla.org/pub/firefox/nightly/2021/02/2021-02-25-21-55-04-mozilla-central/firefox-88.0a1.en-US.win64.zip

Just extract the zip archive and run firefox.exe with your profile. If you could let us know how it works that would be great. Thanks!

Status: NEW → ASSIGNED

Hi,
Thanks Henrik Skupin for giving me that to try,
I tried 88.0a1.en-US.win64.zip and ran it with no change to CPU !

I have to say that I'm really fed up with this. It's quite a serious flaw. I cannot help but wonder how many others are experiencing
something like this. I would imagine that a lot have shutdown built into the bios for overheating, for the CPU running at 100% with just 3 Tabs open. They'd simply figure it was Firefox and use another browser. I'd imagine a lot would not bother reporting this and just stop using firefox !
I've asked quite a few people and they've never heard of such a thing.
When I say that with 3 tabs open at 100% CPU my Desktop was like a furnace I wasn't exaggerating . I could feel the heat with my hand 3 inches above it.
This has been happening since 20th December.

Many thanks for taking the time to read

Flags: needinfo?(tommckey)
Attachment #9205673 - Attachment description: Bug 1684139 - Fix the test fail due to clamped timeouts in workers → Bug 1684139 - Fix the test fail due to clamped timeouts in workers. r?kmag

Hi Again, I'm thinking of doing a complete Fresh Install of Firefox

With hindsight I should have done that ages ago but I really hate having to setup everything
just as I like it and I thought that either WilliamHill.com or FF updates would have sorted it

Is there anything else I can do here before I do that ?
Thanks, Tom
I've also contacted William Hill Tech and they are unaware of any problems, though I'd take that with a pinch of salt.
I have done all the usual things like delete history, cookies and restarted without addons,
Also deleted my userchrome settings (especially for Tabs On Bottom) Please , please , please don't ever take that option away or I may as well desert Firefox as much as I love it.
Also this is not just my desktop but my Laptop too. Identical results.

I just verified the fix myself with the given try build and at least for me the permanent CPU load of about 130% for the web content process is gone, and it consumes not more than around 5% now.

So if you are still seeing this high CPU load for that try build of Firefox would you mind to create a gecko profile while having the page open? That should help us to identify the problem that specifically you have. For steps see the following URL:

https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Reporting_a_Performance_Problem

Please make sure to upload and share the URL with us. Most likely we might have to file a follow-up bug then. Thanks for your help!

Flags: needinfo?(tommckey)

Could I just clarify that after I installed and ran the Nightly I signed in with my Firefox and it synced my addons.
Should I have done this ? Or just left it as it was. Could the sign in be a problem ?
Hope this doesn't sound too infantile, Thanks for helping

Flags: needinfo?(tommckey)

It's not clear to me what specifically you are asking in your last comment. Don't you see the problem anymore under a certain state? I assume you created a fresh profile and signed into sync to get back all the data?

Whatever you did, as long as the high CPU load is present it will be fine to run the profiler with the given try build. If you don't want to share details about open page, installed extensions and such, just untick the checkboxes before uploading the profile.

I do not know what you mean by "Fresh Profile"

I did as you said above "Just extract the zip archive and run firefox.exe "with your profile". I just assumed by "your profile" you meant my usual and only firefox account.

So I extracted the zip and opened the .exe.
After the Nightly build opened I signed in with my Firefox Account . ( what I thought was "my profile" )
The Nightly build then had all my bookmarks and addons.
I then opened William Hill and the CPU was the same 30% +/-

Don't you see the problem anymore under a certain state? ........ I have no idea what you mean by "under a certain state"

I have no experience of Nightly builds OR having 2 Firefox.

I have done a google search about creating a New Profile but how I would tie that in with the Nightly .exe is a bit of a head scratcher for me

Thankyou.

My apologies for the above. I had no intention of creating GIANT BOLD TEXT > Puzzling.

I have created a New Profile called "nightly" but no idea on how to proceed with the nightly.exe

i.e. I do not know how to use the new profile with the nightly .exe
I have tried googling without a plain explanation.

For the Layman this is not straight forward.

Ah, wondering if I run the 88.0a1 .exe ; then when that opens, about:profiles and click on the new nightly profile

Is that the order of the procedure ? Could someone kindly confirm or instruct me how to proceed ?

Thanks

Testing unreleased development builds is not meant to be straightforward.

The fix will make it into regular Firefox eventually. If all goes well, Firefox 88 will be released with the fix on April 20. Until then, I would just ask you to be patient. If this particular web page is critical for you, you can use a different browser just for that page.

OK . I had only installed the nightly .exe on my laptop. Fortunately I created a system restore point before this.
So after the system restore I deleted the old extracted files and ran the zip and ran the extracted nightly .exe

I then typed williamhill.com into the browser and NO CPU spikes :O)

I then signed in with my firefox account and as soon as I did this with williamhill.com open the CPU jumped to 30% :O(

So it's something to do with my account.

Not clear what to do next .Should I uninstall all mozilla firefox files and create a new account, or is there a way
where I can use the same account with a completely new fresh install.
I'm even wondering if I even just use a new account with FF 86.0 would it be OK ???

I'd appreciate instructions to proceed
Thankyou

(In reply to Markus Stange [:mstange] from comment #45)

Testing unreleased development builds is not meant to be straightforward.

The fix will make it into regular Firefox eventually. If all goes well, Firefox 88 will be released with the fix on April 20. Until then, I would just ask you to be patient. If this particular web page is critical for you, you can use a different browser just for that page.

Instead of telling me to use a new browser I think it would have been more constructive to have helped me with my questions of HOW to do the TESTING . Thankyou

Tom, seeing your recent observations I think that it would be best to file a new bug for it. As it looks like it's not related to the improvements that we want to ship with the attached patch on this bug. Mind filing a new bug for your case? We should continue the discussion over there, as long as you see the reported high CPU load with the before-mentioned try build (NOT nightly build - that one doesn't have the fix from this bug yet). Otherwise we can also wait until this bug has been fixed, for a proper baseline of testing. Just in case you don't mind waiting just some more days.

Flags: needinfo?(tommckey)

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+1] from comment #48)

Tom, seeing your recent observations I think that it would be best to file a new bug for it. As it looks like it's not related to the improvements that we want to ship with the attached patch on this bug. Mind filing a new bug for your case? We should continue the discussion over there, as long as you see the reported high CPU load with the before-mentioned try build (NOT nightly build - that one doesn't have the fix from this bug yet). Otherwise we can also wait until this bug has been fixed, for a proper baseline of testing. Just in case you don't mind waiting just some more days.

Hi, Thanks for replying. Just to say I've been messing about "all night" completely uninstalling Mozilla from my PC , trying New Profiles.
At the moment I'm really tired of all this and feel completely demoralized
If the Sun newspaper or any of the Tech sites were to report many instances of this Firefox would be finished.
Who would use a Browser that could melt your Motherboard ? !!
It's a mad mad occurence

How would you suggest we proceed ? Thanks
I mentioned Nightly as it had nightly in the file name for the download 88.0a1

Flags: needinfo?(tommckey)

Tom, for continued work please make sure to focus on the topic. It's not helpful to rant about this one particular issue in each and every comment because it doesn't bring us forward.

We appreciate your feedback and would like to continue finding your specific cause. As such I would suggest to wait until the patches on this bug have been landed. It should only take a couple of days. Once it's for real in Firefox Nightly we should check again, and get a new bug filed when it's still happening. I will let you know when you can test again.

OK Henrik , thanks

Attachment #9205673 - Attachment description: Bug 1684139 - Fix the test fail due to clamped timeouts in workers. r?kmag → Bug 1684139 - Exclude ChromeWorkers from setTimeout/setInterval clamping. r?asuth
Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/d6153b25b156
Implement timer nesting level for workers r=dom-worker-reviewers,asuth
https://hg.mozilla.org/integration/autoland/rev/a3e1c3f3efc1
Adding mozilla specific wpt for timer nesting level in workers r=dom-worker-reviewers,asuth
https://hg.mozilla.org/integration/autoland/rev/e08e70310523
Exclude ChromeWorkers from setTimeout/setInterval clamping. r=asuth
Status: ASSIGNED → RESOLVED
Closed: 3 years ago3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 88 Branch

I can verify that this works fine now with Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0 ID:20210310215846. The CPU load of around 130% of the parent process is down to just 10%.

Tom, can you please download the latest Firefox Nightly and check again? If you still see a high CPU load a new bug would have to be filed, and we have to do further investigation. Thanks!

Flags: needinfo?(tommckey)
Status: RESOLVED → VERIFIED

Hi to Henrik and others,
Finally it's fixed :O) I have 4 WilliamHill.com tabs and about a dozen more open and the CPU is running about 5% +/- . Hooray !

A big thanks to everyone involved and please forgive my rants.

Just to let you know that I created a New Profile and changed the password on my Firefox Account,
which I'm sure you know that resets my addons in case that was a factor.

I'd love to make a donation of £100 if that's possible. A Paypal link for that would be great.

Thanks again, hopefully I can get back to making money again ;O)

Tom.

Flags: needinfo?(tommckey)

This is great to hear, really! It means that it was indeed the same underlying problem, and just something went wrong when testing an earlier build the last time. Now you only have to wait until it makes it to Firefox beta/release. Note that the first Firefox 88 beta will be shipped exactly in a week. Oh, and it's also good to see that you continue using Firefox.

Yes, we happily accept donations in case you wanna do one. Check https://donate.mozilla.org/ for that. Thanks!

Ok I've made the £100 donation with thanks.
I'm really delighted with the fix.

Henrik I'm using the Nightly from the link you provided as my usual Browser. Everything is behaving.
Can I just carry on using it until 88 ?? I'm being asked to Update but declining in case it messes it up again.
Should I just update when Firefox asks me or would I be safer leaving it as it is ?

" the same underlying problem" Do you mean that when I signed into my usual account the problem may have been
something corrupted in the syncing the addons etc ?? And when I changed the password it reset everything ?
Not that important , just curious.

Thanks again, I can't tell you how satisfying it is to have everything working again :O)

Tom McC

(In reply to Tom Mc from comment #57)

Henrik I'm using the Nightly from the link you provided as my usual Browser. Everything is behaving.
Can I just carry on using it until 88 ?? I'm being asked to Update but declining in case it messes it up again.

Feel free to ignore the update request at this point, especially when everything works. But only make sure to actually switch to Firefox Beta once it's on 88 by end of next week.

" the same underlying problem" Do you mean that when I signed into my usual account the problem may have been
something corrupted in the syncing the addons etc ?? And when I changed the password it reset everything ?
Not that important , just curious.

Hard to say without having a profile that still has those files. If you have them please re-test. But all this will be off-topic on this bug. So in case something is broken please file a new one. Thanks!

Regressions: 1694647
Performance Impact: --- → P2
Whiteboard: [qf:p2:resource]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: