Closed Bug 2067306 Opened 2 months ago Closed 1 month ago

Multi-second main thread hangs on macOS 26 (Tahoe) caused by system menu indexing (NSMenu _simulateOpening) re-rasterizing all bookmark/history favicons via nsMenuItemIconX

Categories

(Core :: Widget: Cocoa, defect)

Firefox 154
Unspecified
macOS
defect

Tracking

()

RESOLVED DUPLICATE of bug 2002102

People

(Reporter: t.m.meijers, Unassigned)

References

Details

Attachments

(8 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:154.0) Gecko/20100101 Firefox/154.0

Steps to reproduce:

Use Firefox normally on macOS 26 (Tahoe) for an hour or so, switching to other apps and back once in a while.

Actual results:

Firefox freezes for several seconds at a time (macos beachball cursor), most often right when switching back to it from another app. Right after a reboot everything is fast, but within roughly an hour of use the hangs start and they get worse the longer the machine is up. This happens in a clean profile with all add-ons disabled, and it survived a clean reinstall of Firefox and even a clean install of macOS.

Additional information:

Firefox 154.0.1 (20260824154132) release, macOS 26.5.2 (25F84), MacBook Pro M3 Pro, 36 GB RAM. Apple Intelligence is not active on this machine (Siri is off and it is not even available due to a system/Siri language mismatch), which matters for what follows. This probably belongs in Core :: Widget: Cocoa.

I ran a watchdog that pinged the parent process every 10 seconds and ran /usr/bin/sample the moment a ping stalled, so I have native stacks from inside the hangs. Symbolicated with symbolication.services.mozilla.com (XUL arm64 debugID 9547FBD571153F59B01C75A8B7E3CC440), the main thread during a caught 3.2 second hang looks like this:

nsAppShell::ProcessGeckoEvents
  NS_ProcessPendingEvents
    TaskController::DoExecuteNextTaskOnlyMainThreadInternal
      mozilla::image::AsyncNotifyRunnable::Run
        mozilla::image::ProgressTracker::SyncNotify
          imgRequestProxy::Notify
            mozilla::widget::IconLoader::Notify
              nsMenuItemIconX::OnComplete
                +[MOZIconHelper iconImageFromImageContainer:withSize:svgContext:scaleFactor:]
                  nsCocoaUtils::CreateDualRepresentationNSImageFromImageContainer
                    nsCocoaUtils::CreateNSImageFromImageContainer
                      nsCocoaUtils::CreateNSImageFromCGImage
                        +[NSGraphicsContext graphicsContextWithBitmapImageRep:]
                          NSNewBitmapBackingStore -> CGBitmapAllocateData -> mmap

So the parent is rasterizing menu item favicons into 1x+2x NSBitmapImageReps on the main thread. The interesting part is what triggers it. Other samples taken during active use show the OS itself walking the Firefox menu tree:

__CFRunLoopDoBlocks
  UIIntelligenceSupport (Apple private framework, runs in-process)
    AppKit
      -[NSMenu _simulateOpening:]
        -[NSMenu _forEachLinkedMenu:]
          -[NSMenu _sendAndRecordMenuOpeningNotification]
            -[NSMenu _sendMenuOpeningNotification:]
              (XUL) MenuDelegate menuWillOpen:

On Tahoe, intelligencecontextd periodically asks every running app to "collect fragments" (visible in the unified log, subsystem com.apple.UIIntelligenceSupport). Inside the app, UIIntelligenceSupport opens every menu with the private -[NSMenu _simulateOpening:]. Firefox cannot tell this apart from a real menu open, so each pass fully populates the Bookmarks and History menus and reloads and re-rasterizes every favicon, on the main thread, every time.

Some numbers from back-to-back 3 second sample captures during 2 minutes of normal use:

  • harvest passes arrived about every 30 seconds, and a single _simulateOpening pass blocked the main thread for up to 1.6 seconds
  • menu icon rasterization showed up in 11 of 35 samples, roughly 10% of all main thread time
  • parent RSS churned between 3.3 GB and 7.6 GB within about 40 seconds during these storms, and macOS's resource monitor flags the parent for gigabytes of dirtied file-backed memory almost daily

To confirm causality I paused the trigger with kill -STOP intelligencecontextd and repeated the same 2.5 minutes of active use: 0 of 43 samples contained _simulateOpening or any icon rasterization, ping latency stayed flat around 330 ms and RSS stayed stable. After kill -CONT the behavior comes back. Note again that this machine has Apple Intelligence off, the harvesting runs anyway (I will file an Apple Feedback report about that side of it).

Why it gets worse with uptime: the History menu keeps changing while browsing, so the collection keeps re-running over growing menus. My bookmarks are small (143 bookmarks, 28 folders, max depth 3, no cycles), so this is not the bookmark cycle problem from bug 1979283, which is fixed in my version anyway.

I suspect this is the actual cause behind several existing Tahoe hang reports, at least bug 1992841 and possibly bug 1988943, bug 1982717 and bug 1991301. Bug 2002102 is about menu population cost in general, but in my measurements the icon rasterization is the dominant cost.

Possible directions: recognize simulated menu opens and skip favicon loading there, and/or cache the rasterized NSImages instead of rebuilding every icon on every pass even when nothing changed.

I am attaching the sample taken during the 3.2 s hang. I also have a sample of a complete _simulateOpening pass, a responsiveness log covering fresh boot through degraded state, and the unified log extract of UIIntelligenceSupport activity in the firefox process, which I will attach right after filing.

Expected results:

No hangs.

The Bugbug bot thinks this bug should belong to the 'Toolkit::Places' component, but is not confident enough to move the bug to that component.

Component: Untriaged → General

:tschuster at a glance does this look like it would be relevant to your work to get image decoding off the main thread?

Flags: needinfo?(tschuster)
OS: Unspecified → macOS

Really not sure what this code is, but I think even if we re-encode the history images in a child process, in the parent we would still decode again and give the image to the platform code.

Flags: needinfo?(tschuster)

The severity field is not set for this bug.
:mstriemer, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(mstriemer)
Component: General → Widget: Cocoa
Flags: needinfo?(mstriemer)
Product: Firefox → Core

Could you try a few things and let me know the answers to the questions below?

  1. Once the hangs have started, quit and restart Firefox only, without rebooting the Mac. Do the hangs go away after the restart? If they do, how long does it take for them to come back?

  2. Could you capture two profiles with the Firefox Profiler, one about 2 minutes after starting Firefox and one once the hangs have started?

One-time setup:

  • Open about:profiling and click "Enable Profiler Menu Button".
  • On the same page, set "Buffer size" to 1 GB.
  • In about:config, set devtools.chrome.enabled to true.

Capture:

  • Press Cmd+Shift+J to open the Browser Console, paste this line and press Enter:
[SessionStore.getClosedTabCount(), SessionStore.getClosedWindowCount()]
  • Press Cmd+Shift+1 to start recording, then keep using Firefox normally, switching to other apps and back.
  • Right after a hang, press Cmd+Shift+2.
  • In the new tab, click "Upload Local Profile".
  • Paste the https://share.firefox.dev/... link here, together with the Browser Console output and the number of open Firefox windows.
  1. Could you attach the unified log extract of UIIntelligenceSupport activity you mentioned in comment 0? If possible, one from shortly after a reboot and one from once the hangs have started.
Severity: -- → S3

Comment on attachment 9655482 [details]
Findings based on the steps that were requested

(sorry, didn't realize the summary modal would post it as a plain txt file, here's the text as a comment too for readability in case that matters)

Thanks for the questions. I did this today (2026-10-07) on Firefox 157.0 (20261005135250) and macOS 26.5.2 (25F84). I didn't reboot for this round. For the "shortly after a reboot" log I've attached the extract I had from 2026-08-27.

1. Restarting only Firefox

The hangs did not go away after restarting Firefox.

  • I restarted Firefox at 17:03. The first hang came at 17:06:46, about 3.5 minutes later (4.5 s, profile A). The next one was at 17:17 (6.2 s), and there were more during the evening, the last at 20:21 (profile B).
  • Parent process memory was 1.1 GB just after the restart and 7.3 GB three hours later. During each hang it went up by several GB (1.1 to 6.1 GB at 17:06, 4.7 to 8.8 GB at 20:21).

Before the restart, Firefox had been running for 5 days. Normally I keep intelligencecontextd paused with SIGSTOP as a workaround. When I resumed it at 16:52 for this test, it sent about 1,100 requests to Firefox within 5 minutes. Firefox stopped responding and I had to force quit it at 16:57. I'm mentioning this because it shows up in the logs; I don't think it's the normal situation.

2. Profiles

Both were uploaded without screenshots and without resource URLs.

Profile A Profile B
Firefox running for 3.6 min 3 h 18 min
Main thread blocked 4.5 s 5.4 s (in 3 parts, longest 3.0 s)
Max event delay 4.6 s 6.0 s
Parent memory during the hang 1.1 to 6.1 GB 4.7 to 8.8 GB

The Browser Console line didn't work for me (ReferenceError: SessionStore is not defined). Instead I read the numbers from the session file (sessionstore-backups/recovery.jsonlz4) once a minute during the whole test. They didn't change:

  • closed tabs: 62 (25 in the open window, 37 in closed windows)
  • closed windows: 5
  • open Firefox windows: 1 (with 12 to 16 tabs)

3. Unified log extracts (attached)

  • ff_uiintel_2026-08-27_after_reboot.txt: UIIntelligenceSupport in the firefox process (Firefox 154.0.1), 23:14 to 00:12, starting 15 minutes after a reboot. In the probe log attached earlier, the first slow response (over 1 s) was at 23:26, 26 minutes after boot.
  • ff_uiintel_2026-10-07.txt: the same for today, 16:50 to 20:30.
  • intelligencecontextd_spotlight_firefox_2026-10-07.txt: the intelligencecontextd side for today. I left out lines about other third-party apps.
  • harvest_vs_spotlight_2026-10-07.txt: a table of today's Spotlight sessions and the requests Firefox got (see below).

Something I noticed in the logs

The hangs today came right after I opened Spotlight. Each time Spotlight connects, intelligencecontextd starts a request with a 0.75 s timeout that names one app:

starting RequestID(...) for client Spotlight: RequestParameters(timeout: 0.75 sec,
  requestedComponents: (commands), targetedAppBundleIdentifiers: ["org.mozilla.firefox"], ...)

Between 17:03 and 20:30 I opened Spotlight 17 times. In 8 of those the request named Firefox, and each time there was a second one about 1.8 s later. All 16 timed out. Firefox's answers arrived 2.5 to 5 s after each request and were logged as "received fragment ... for invalid or expired request". In the other 9 sessions the request named another app. Siri is turned off on this Mac, but each Spotlight session also came with two requests from client Siri, and Firefox answered those within milliseconds.

In comment 0 I wrote that the requests came about every 30 seconds and that the hangs started after about an hour of uptime. Today it looked different: the requests came when I opened Spotlight, and the first hang came 3.5 minutes after restarting Firefox.

Thank you for the additional data points. Could you also do the following?

  1. Open "Tools" > "Browser Tools" > "Browser Console" (devtools.chrome.enabled should still be true from last time), paste the following and press Enter:
(async () => {
  const { PlacesUtils } = ChromeUtils.importESModule("resource://gre/modules/PlacesUtils.sys.mjs");
  const found = [];
  const walk = (node, path) => {
    const here = path ? `${path} > ${node.title}` : node.title;
    if (node.uri?.startsWith("place:")) {
      found.push(`${here}: ${node.uri}`);
    }
    for (const child of node.children || []) {
      walk(child, here);
    }
  };
  walk(await PlacesUtils.promiseBookmarksTree(), "");
  console.log(found.join("\n") || "no place: bookmarks");
})();

Could you paste the output here?

  1. Open "Bookmarks" > "Manage Bookmarks", choose "Import and Backup" > "Backup…" and save the file. (Please be careful with this step and ensure that the file is created before continuing.)

  2. In the same window, delete the bookmarks that step 1 listed. Then open Spotlight a few times while Firefox is running. Do the hangs still happen?

  3. To get the bookmarks back, open "Bookmarks" > "Manage Bookmarks" and choose "Import and Backup" > "Restore" > "Choose File…" with the file from step 2. This replaces all bookmarks with the backup, so any bookmark changes made after step 2 will be lost.

Flags: needinfo?(t.m.meijers)

Thanks for the quick response!

  1. Here's the output of the snipper:

    unfiled > History: place:type=3&sort=4
    unfiled > Tags: place:type=6&sort=1
    unfiled > Downloads: place:transition=7&sort=4
    
  2. I made the backup, deleted these three bookmarks and opened Spotlight a number of times while Firefox was running. I didn't restart Firefox for this; it was the same process as in my previous comment, by then running for about 17 hours.

    The hangs did not happen. In the intelligencecontextd log, the Spotlight commands requests to Firefox were answered in 70-80 ms (one at 516 ms right after I resumed the daemon), and none of the 10 timed out. Yesterday the same requests took 2.5-5 s and all of them timed out.

Flags: needinfo?(t.m.meijers)

Okay thank you! Deleting those three bookmarks took the requests from 2.5 to 5 s down to 70 to 80 ms in the same Firefox process, so they look like the cause. They're saved searches (place: queries) that list your entire history, all downloads and all tags. Because they sit in "Other Bookmarks", they show up in the "Bookmarks" menu, and each time macOS walks that menu, Firefox appears to rebuild them from scratch, thousands of entries every time.

This is the same problem as bug 2002102. Two other people had these queries in "Other Bookmarks" as well (bug 2005154 and bug 2002102 comment 8), so I'm closing this one as a duplicate. Your profiles and logs pinned down the trigger and the cost much more precisely than we had before, and they'll help with the fix there.

If you restore the backup from step 2, those three bookmarks will come back, so you'd want to delete them again afterwards. Keeping them deleted should be safe.

Status: UNCONFIRMED → RESOLVED
Closed: 1 month ago
Duplicate of bug: 2002102
Resolution: --- → DUPLICATE

Glad I could be of help! The slowdowns were driving me mad and I almost stopped using Firefox but I did not want to move back to Chrome and tried to investigate more. I hope you have almost all the infromation that you need to fix it. Thank you too for your work and help generating reports!

In case others find this thread, this the workaround I have for now:
Because each time you open Spotlight, the macOS process intelligencecontextd makes Firefox rebuild its menus, which freezes it for several seconds. As a workaround I keep that process paused. Save this as pause-intelligencecontextd.sh and make it executable (chmod +x):

#!/bin/bash
while true; do
  for pid in $(pgrep -x intelligencecontextd); do
    state=$(ps -o state= -p "$pid")
    [ "${state#T}" = "$state" ] && kill -STOP "$pid"
  done
  sleep 30
done

MacOS continually reboots the process, so it needs to be killed every 30 seconds.
Now save the following as ~/Library/LaunchAgents/local.pause-intelligencecontextd.plist, with your script's path filled in:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>local.pause-intelligencecontextd</string>
  <key>ProgramArguments</key><array><string>/path/to/pause-intelligencecontextd.sh</string></array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
</dict></plist>

Start it: launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/local.pause-intelligencecontextd.plist
Undo: launchctl bootout gui/$(id -u)/local.pause-intelligencecontextd && killall -CONT intelligencecontextd

Side effects:

  • Spotlight can't search app menu commands.
  • Requests pile up while the process is paused. On resume they all hit Firefox at once and freeze it, so quit Firefox before undoing.
  • It's a hack; a macOS update may break it.
See Also: → 2091501
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: