Closed Bug 1989709 Opened 1 year ago Closed 1 year ago

NotificationDB takes a lot of time on taskSave and JSON.stringify

Categories

(Core :: DOM: Notifications, defect)

Firefox 143
defect

Tracking

()

RESOLVED FIXED
145 Branch
Tracking Status
firefox145 --- fixed

People

(Reporter: arcadiy, Assigned: saschanaz)

References

(Depends on 1 open bug)

Details

Attachments

(3 files, 1 external file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0

Steps to reproduce:

Ever since 141 there is an issue where when Firefox produces a notification popup via KDE plasma the entire Firefox stalls for a second, including when playing a video. When clearing all notifications from KDE plasma Firefox main process starts consuming CPU at a high rate with a stall/hickup every 300/500ms, basically every other keystroke.
No specific Firefox process is implicated as you can see in a screenshot.
No other application running suffers from this.

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Gtk' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Widget: Gtk
Product: Firefox → Core

Hi,

This issue appears similar to bug 1984438, which also involves notification system interactions causing Firefox performance problems on KDE/Linux.

To help investigate this further, could you please capture a Firefox profiler trace during the freeze/stall? Here's how:

  1. Navigate to https://profiler.firefox.com/
  2. Click "Start recording"
  3. Trigger a KDE notification that causes the freeze
  4. After the stall occurs, click "Capture" in the profiler
  5. Upload the profile and share the link here

This will help us identify what's blocking the main thread during the notification event.

Thanks!

Kagami, this bug appears very similar to bug 1984438 where notification system interactions cause Firefox hangs on KDE/Linux.

Both involve notification-related blocking of the main thread. In bug 1984438, we identified that libnotify's synchronous D-Bus communication was the culprit.

We should consider moving the notification handling off the main thread to prevent these KDE notification-triggered stalls.

Flags: needinfo?(krosylight)

Alternatively we could import libnotify code into firefox-main and patch it for our purpose (and eventually upstream it). Wdyt? (Off-the-main-thread is really a workaround than a real fix...)

Chromium has its own notification backend which is independent from libnotify, we could do the same if it makes sense.

We should also consider removing sync calls in our own code: https://searchfox.org/firefox-main/search?q=g_dbus_proxy_call_sync&path=&case=true&regexp=false

When clearing all notifications from KDE plasma Firefox main process starts consuming CPU at a high rate with a stall/hickup every 300/500ms, basically every other keystroke.

But this doesn't make sense to me, that's nothing to do with sync dbus call. Arcadiy, would you mind creating a performance profile with https://profiler.firefox.com? You can use https://www.bennish.net/web-notifications.html to trigger notifications and then clear all.

Component: Widget: Gtk → Alerts Service
Flags: needinfo?(krosylight) → needinfo?(arcadiy)
Product: Core → Toolkit

And also, when clearing happens, how many notifications are involved?

(In reply to Kagami Rosylight [:saschanaz] (they/them) from comment #5)

And also, when clearing happens, how many notifications are involved?

I will run profile as requested once the problem reappears. I can't tell you how many but usually "a lot" as when I leave the laptop asleep while traveling for several hours, coming back and removing all Twitter notifications usually results in massive CPU consumption and stalls for tens of minutes. But it's hard to say because notifications also expire so they don't accumulate indefinitely.

Can you provide some magnitude, like, 10+, 100+, even 1000+?

I'll try to get an estimate next time.

(In reply to Kagami Rosylight [:saschanaz] (they/them) from comment #4)

Alternatively we could import libnotify code into firefox-main and patch it for our purpose (and eventually upstream it). Wdyt? (Off-the-main-thread is really a workaround than a real fix...)

It would be better to check with upstream if they would accept the solution or patch.
If they accept the proposal, we should just land the patch at the upstream instead of importing the code. If it changes the signature of API or introduce a new API, we could use weak symbols for the new API to use it if available.

Profile: https://share.firefox.dev/3IBantp

The number of notifications is probably in low hundreds.

Flags: needinfo?(arcadiy)

Here is another one with the following scenario:

  1. Begins normally
  2. A single notification arrives, causing a stutter.
  3. Single notification is dismissed.
  4. All notifications cleared, CPU maxes out, stutter constant.

https://share.firefox.dev/4gFopXC

Thank you! In this case actually it's fully about NotificationDB being slow, nothing to do with libnotify. Changing the component.

Component: Alerts Service → DOM: Notifications
Product: Toolkit → Core
Summary: Short freeze/stall with KDE notifications popup from Firefox on Wayland/kwin → NotificationDB takes a lot of time on taskSave and JSON
Summary: NotificationDB takes a lot of time on taskSave and JSON → NotificationDB takes a lot of time on taskSave and JSON.stringify

One more thing, if you do:

  1. Fully close Firefox and reopen
  2. Open about:support
  3. Open the profile folder
  4. Open notificationstore.json

Is it empty like {} or is the file super big?

Depends on: 1884045
Flags: needinfo?(arcadiy)

It's 135.8MB. :)

Flags: needinfo?(arcadiy)
Attached image notificationstore.json β€”

In the meantime please remove the file and restart Firefox, and then it should be fast again.

Assignee: nobody → krosylight
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

I see twitter notifications from 4 years ago! Are they not garbage-collected??

{
  "https://twitter.com": {
    "{f54d5fa3-219e-498a-9a4c-85d516746393}": {
      "id": "{f54d5fa3-219e-498a-9a4c-85d516746393}",
      "title": "Chris B - NSF",
      "dir": "auto",
      "lang": "",
      "body": "RT @nextspaceflight: The Flight Termination System (FTS) has still not been installed on Starship SN15. The odds of a launch attempt tomorrow are deteriorating, but perhaps they plan to do it last minute.",
      "tag": "tweet_with_badge-1387920630763376643",
      "icon": "https://pbs.twimg.com/profile_images/1121126296086618116/XdSiqigA_reasonably_small.png",
      "alertName": "https://twitter.com#tag:tweet_with_badge-1387920630763376643",
      "timestamp": 1619741063036,
      "origin": "https://twitter.com",
      "data": "AgAAAAAA8f8AAAAACAD//wQAAIAEAP//bGFuZwAAAAACAACABAD//2VuAAAAAAAACwAAgAQA//9idW5kbGVfdGV4dAAAAAAAUwAAgAQA//97bnVtX3RvdGFsLCBudW1iZXJ9IG5ldyB7bnVtX3RvdGFsLCBwbHVyYWwsIG9uZSB7aW50ZXJhY3Rpb259IG90aGVyIHtpbnRlcmFjdGlvbnN9fQAAAAAABAAAgAQA//90eXBlAAAAABAAAIAEAP//dHdlZXRfd2l0aF9iYWRnZQMAAIAEAP//dXJpAAAAAAArAACABAD//y9uZXh0c3BhY2VmbGlnaHQvc3RhdHVzLzEzODc5MTM0OTYyNjQ3OTgyMTQAAAAAAA0AAIAEAP//aW1wcmVzc2lvbl9pZAAAACAAAIAEAP//ODA5ZjAwNzliNjMzNGZkMmFiZmY2ODAyM2Y5NDI1NDEFAACABAD//3RpdGxlAAAADQAAgAQA//9DaHJpcyBCIC0gTlNGAAAABAAAgAQA//9ib2R5AAAAAMwAAIAEAP//UlQgQG5leHRzcGFjZWZsaWdodDogVGhlIEZsaWdodCBUZXJtaW5hdGlvbiBTeXN0ZW0gKEZUUykgaGFzIHN0aWxsIG5vdCBiZWVuIGluc3RhbGxlZCBvbiBTdGFyc2hpcCBTTjE1LiBUaGUgb2RkcyBvZiBhIGxhdW5jaCBhdHRlbXB0IHRvbW9ycm93IGFyZSBkZXRlcmlvcmF0aW5nLCBidXQgcGVyaGFwcyB0aGV5IHBsYW4gdG8gZG8gaXQgbGFzdCBtaW51dGUuAAAAAAMAAIAEAP//dGFnAAAAAAAkAACABAD//3R3ZWV0X3dpdGhfYmFkZ2UtMTM4NzkyMDYzMDc2MzM3NjY0MwAAAAANAACABAD//3NjcmliZV90YXJnZXQAAAAFAACABAD//3R3ZWV0AAAACgAAgAQA//90b3RhbENvdW50AAAAAAAAAQAAAAMA//8AAAAAEwD//w==",
      "mozbehavior": "{\"noclear\":false,\"noscreen\":false,\"showOnlyOnce\":false,\"soundFile\":\"\"}",
      "serviceWorkerRegistrationScope": "https://twitter.com/"
    },
    "{5a7ca440-b68f-4905-97e4-268e15205c69}": {
      "id": "{5a7ca440-b68f-4905-97e4-268e15205c69}",
      "title": "Not the Bee",
      "dir": "auto",
      "lang": "",
      "body": "As this \"pastor\" so colorfully illustrates, \"antiracism\" is nothing more than actual racists discovering a way to trumpet their racism in civil society notthebee.com/article/as-thi…",
      "tag": "tweet_with_badge-1387920045322510336",
      "icon": "https://pbs.twimg.com/profile_images/1299007907623825411/Vo7e-cEQ_reasonably_small.jpg",
      "alertName": "https://twitter.com#tag:tweet_with_badge-1387920045322510336",
      "timestamp": 1619741063039,
      "origin": "https://twitter.com",
      "data": "AgAAAAAA8f8AAAAACAD//wQAAIAEAP//bGFuZwAAAAACAACABAD//2VuAAAAAAAACwAAgAQA//9idW5kbGVfdGV4dAAAAAAAUwAAgAQA//97bnVtX3RvdGFsLCBudW1iZXJ9IG5ldyB7bnVtX3RvdGFsLCBwbHVyY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screen\":false,\"showOnlyOnce\":false,\"soundFile\":\"\"}",
      "serviceWorkerRegistrationScope": "https://twitter.com/"
    },
    "{b32870e3-7340-45b2-9691-8b1e44bb2ff3}": {
      "id": "{b32870e3-7340-45b2-9691-8b1e44bb2ff3}",
      "title": "OSINTtechnical",
      "dir": "auto",
      "lang": "",
      "body": "Blinken says Russia has pulled back some of the troops it deployed over the past month. twitter.com/60Minutes/stat…",
      "tag": "tweet_with_badge-1387921293706661893",
      "icon": "https://pbs.twimg.com/profile_images/1191175818933932032/W4GF6Nbe_reasonably_small.jpg",
      "alertName": "https://twitter.com#tag:tweet_with_badge-1387921293706661893",
      "timestamp": 1619741197819,
      "origin": "https://twitter.com",
      "data": "AgAAAAAA8f8AAAAACAD//wQAAIAEAP//bGFuZwAAAAACAACABAD//2VuAAAAAAAACwAAgAQA//9idW5kbGVfdGV4dAAAAAAAUwAAgAQA//97bnVtX3RvdGFsLCBudW1iZXJ9IG5ldyB7bnVtX3RvdGFsLCBwbHVyYWwsIG9uZSB7aW50ZXJhY3Rpb259IG90aGVyIHtpbnRlcmFjdGlvbnN9fQAAAAAABAAAgAQA//90eXBlAAAAABAAAIAEAP//dHdlZXRfd2l0aF9iYWRnZQMAAIAEAP//dXJpAAAAAAAqAACABAD//y9Pc2ludHRlY2huaWNhbC9zdGF0dXMvMTM4NzkyMTI5MzcwNjY2MTg5MwAAAAAAAA0AAIAEAP//aW1wcmVzc2lvbl9pZAAAACAAAIAEAP//NDg4NDU1NGI3ZTMzNGExOGI4Mjg3OTg0NjIzM2RhOWQFAACABAD//3RpdGxlAAAADgAAgAQA//9PU0lOVHRlY2huaWNhbAAABAAAgAQA//9ib2R5AAAAAHMAAAAEAP//QgBsAGkAbgBrAGUAbgAgAHMAYQB5AHMAIABSAHUAcwBzAGkAYQAgAGgAYQBzACAAcAB1AGwAbABlAGQAIABiAGEAYwBrACAAcwBvAG0AZQAgAG8AZgAgAHQAaABlACAAdAByAG8AbwBwAHMAIABpAHQAIABkAGUAcABsAG8AeQBlAGQAIABvAHYAZQByACAAdABoAGUAIABwAGEAcwB0ACAAbQBvAG4AdABoAC4AIAB0AHcAaQB0AHQAZQByAC4AYwBvAG0ALwA2ADAATQBpAG4AdQB0AGUAcwAvAHMAdABhAHQAJiAAAAMAAIAEAP//dGFnAAAAAAAkAACABAD//3R3ZWV0X3dpdGhfYmFkZ2UtMTM4NzkyMTI5MzcwNjY2MTg5MwAAAAANAACABAD//3NjcmliZV90YXJnZXQAAAAFAACABAD//3R3ZWV0AAAACgAAgAQA//90b3RhbENvdW50AAAAAAAAAQAAAAMA//8AAAAAEwD//w==",
      "mozbehavior": "{\"noclear\":false,\"noscreen\":false,\"showOnlyOnce\":false,\"soundFile\":\"\"}",
      "serviceWorkerRegistrationScope": "https://twitter.com/"
    },
    "{e164d0a9-ea1c-40d4-928e-67601ded305a}": {
      "id": "{e164d0a9-ea1c-40d4-928e-67601ded305a}",
      "title": "Not the Bee",
      "dir": "auto",
      "lang": "",
      "body": "Biden's Defense Department denies permit to \"Rolling to Remember,\" jeopardizing 32-year Memorial Day tradition honoring our veterans. notthebee.com/article/bidens…",
      "tag": "tweet_with_badge-1388562263074918403",
      "icon": "https://pbs.twimg.com/profile_images/1299007907623825411/Vo7e-cEQ_reasonably_small.jpg",
      "alertName": "https://twitter.com#tag:tweet_with_badge-1388562263074918403",
      "timestamp": 1619894017052,
      "origin": "https://twitter.com",
      "data": "AgAAAAAA8f8AAAAACAD//wQAAIAEAP//bGFuZwAAAAACAACABAD//2VuAAAAAAAACwAAgAQA//9idW5kbGVfdGV4dAAAAAAAUwAAgAQA//97bnVtX3RvdGFsLCBudW1iZXJ9IG5ldyB7bnVtX3RvdGFsLCBwbHVyYWwsIG9uZSB7aW50ZXJhY3Rpb259IG90aGVyIHtpbnRlcmFjdGlvbnN9fQAAAAAABAAAgAQA//90eXBlAAAAABAAAIAEAP//dHdlZXRfd2l0aF9iYWRnZQMAAIAEAP//dXJpAAAAAAAnAACABAD//y9Ob3RfdGhlX0JlZS9zdGF0dXMvMTM4ODU2MjI2MzA3NDkxODQwMwANAACABAD//2ltcHJlc3Npb25faWQAAAAgAACABAD//2Y1NDNmZjIwZTdkZjRiYzE5NmU4ODEyOTk4YzNkODk4BQAAgAQA//90aXRsZQAAAAsAAIAEAP//Tm90IHRoZSBCZWUAAAAAAAQAAIAEAP//Ym9keQAAAACjAAAABAD//0IAaQBkAGUAbgAnAHMAIABEAGUAZgBlAG4AcwBlACAARABlAHAAYQByAHQAbQBlAG4AdAAgAGQAZQBuAGkAZQBzACAAcABlAHIAbQBpAHQAIAB0AG8AIAAiAFIAbwBsAGwAaQBuAGcAIAB0AG8AIABSAGUAbQBlAG0AYgBlAHIALAAiACAAagBlAG8AcABhAHIAZABpAHoAaQBuAGcAIAAzADIALQB5AGUAYQByACAATQBlAG0AbwByAGkAYQBsACAARABhAHkAIAB0AHIAYQBkAGkAdABpAG8AbgAgAGgAbwBuAG8AcgBpAG4AZwAgAG8AdQByACAAdgBlAHQAZQByAGEAbgBzAC4AIABuAG8AdAB0AGgAZQBiAGUAZQAuAGMAbwBtAC8AYQByAHQAaQBjAGwAZQAvAGIAaQBkAGUAbgBzACYgAAADAACABAD//3RhZwAAAAAAJAAAgAQA//90d2VldF93aXRoX2JhZGdlLTEzODg1NjIyNjMwNzQ5MTg0MDMAAAAADQAAgAQA//9zY3JpYmVfdGFyZ2V0AAAABQAAgAQA//90d2VldAAAAAoAAIAEAP//dG90YWxDb3VudAAAAAAAAAEAAAADAP//AAAAABMA//8=",
      "mozbehavior": "{\"noclear\":false,\"noscreen\":false,\"showOnlyOnce\":false,\"soundFile\":\"\"}",
      "serviceWorkerRegistrationScope": "https://twitter.com/"
    },

(In reply to Kagami Rosylight [:saschanaz] (they/them) from comment #17)

Gah. My fault. Patch coming soon.

Thanks so much!

Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 145 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: