iOS icon indicating copy to clipboard operation
iOS copied to clipboard

High CPU load on macOS

Open wolph opened this issue 2 years ago • 27 comments

Device model, version and app version

Model Name: Macbook pro 16" 2019 macOS Version: 12.6.4 (21G526) monterey App Version: 2023.2.1 (2023.452) Safari Version: Version 16.4 (17615.1.26.101.9, 17615)

Home Assistant Core Version Home Assistant 2023.8.0

Describe the bug The OS X app uses a significant amount of CPU when it's simply idling in the background (window closed). I've already tried to disable as many sensors as I can but it doesn't appear to make much difference.

I should note that it's likely not the safari component because when opening home assistant in safari the CPU load is significantly less.

While I'm not too experienced in OS X development I can certainly help debug the issue (i.e. profile using xcode or instruments)

Restarting the app might reduce the cpu load a little but it's varying too much to be certain of that. In any case, when my computer is idling it's by far the most resource intensive app running, even though I've got 3 pycharm windows open, 3 vscode windows, 5 chrome windows with about 30 tabs in total. It is definitely using an excessive amount of CPU power.

To Reproduce

Run the Home Assistant app.

Expected behavior

No significant amount of CPU load while idling.

** Additional information**

I've included two samples, one after running for a while and one after a restart of the app.

Sample of Home Assistant After restart.txt Sample of Home Assistant.txt

wolph avatar Aug 04 '23 13:08 wolph

I had similar issues both on my Intel Mac and Apple Silicon. I noticed the problem is when there is a connection issue. For example after sleep etc. Also once i had HUGE memory leak app took about 96GB of virtual memory.

imkebe avatar Aug 20 '23 18:08 imkebe

I'm having the same problem, and its causing me to see Home Assistant Macos as somewhat of a parasite to my mac's performance, as almost always when i get stuttering and battery issues, its this app unnecessarily using a lot of resources in the background

ShadowJonathan avatar Nov 28 '23 07:11 ShadowJonathan

So far I've not really been able to debug it myself... I've tried analysing the app using Instruments but because there are no debug symbols that's largely useless.

I've also tried compiling the app myself but for some reason xcode is not happy and giving me 514 errors. Not entirely sure what's wrong but for some reason it doesn't seem to recognise the L10n namespace and several others. I can investigate further if anyone has a hint as to what could be the cause:

▸ ❌  Sources/Extensions/NotificationContent/MapViewController.swift:150:25: cannot find 'L10n' in scope
▸             if title == L10n.Extensions.Map.Location.original {
▸                             ^~~~
▸ ❌  Sources/Extensions/NotificationContent/MapViewController.swift:152:32: cannot find 'L10n' in scope
▸             } else if title == L10n.Extensions.Map.Location.new {
▸                         ^~~~
▸ Compiling CameraStreamHandler.swift
▸ ❌  Sources/Extensions/NotificationContent/CameraStreamHandler.swift:11:15: cannot find type 'HomeAssistantAPI' in scope
▸     init(api: HomeAssistantAPI, response: StreamCameraResponse) throws
▸                                ^~~~
▸ ❌  Sources/Extensions/NotificationContent/CameraStreamHandler.swift:11:43: cannot find type 'StreamCameraResponse' in scope
▸     init(api: HomeAssistantAPI, response: StreamCameraResponse) throws
▸               ^~~~~~~~~~~~~~~~

wolph avatar Dec 11 '23 01:12 wolph

Same issue on osx 14.2.1

johntdyer avatar Jan 08 '24 15:01 johntdyer

For the memory leak we have a duplicate issue being worked on here: https://github.com/home-assistant/iOS/issues/2101

For CPU usage, do you still see the issue on version 2024.4? Let me know so I can hopefully close this issue

bgoncal avatar Apr 17 '24 11:04 bgoncal

I remember closing home assistant multiple times lately due to my Mac being slow, it may be placebo, but I want to observe for a few more moments before I'd say yes or no

ShadowJonathan avatar Apr 17 '24 13:04 ShadowJonathan

I can confirm that latest 2024.4 (2024.624) still has an issue. It happens for me when the Companion App was connected to the HA service, disconnect my MacBook from the network (by physically moving away), bring it back and connect to the network again. So the service is not available and then available again. Then i saw that my RAM is jumping 1-4 MB every second.

imkebe avatar Apr 28 '24 15:04 imkebe

Please try 2024.4.1 which is in TestFlight beta

bgoncal avatar Apr 28 '24 15:04 bgoncal

I've been trying for a little while but OS X refuses to run the app. Starting it the normal way I get this: image

Trying it from the commandline I get:

zsh: killed     ./Home\ Assistant

I'm sure that's not related to this issue though... could be an older OS X issue or perhaps I downloaded the wrong build file.

wolph avatar May 11 '24 13:05 wolph

Removing the Thread integration (which I wasn’t using) seems to have resolved these issues for me.

benediktkr avatar Jun 12 '24 17:06 benediktkr

I started noticing this problem as well recently (high CPU usage). It seems to come and go, but I've noticed it a few times now.

JonLaliberte avatar Jun 19 '24 21:06 JonLaliberte

Same here, high CPU load causing fans to go wild. MacBook Pro running Sonoma. I conform that removing the Thread integration solves the problem....

frederick-launoy avatar Jun 24 '24 09:06 frederick-launoy

I actually use Thread for some devices, so removing it is a no-go for me.

ShadowJonathan avatar Jun 24 '24 09:06 ShadowJonathan

I actually use Thread for some devices, so removing it is a no-go for me.

Understand, just wanted to post this info as this can help whoever is analysing this problem to understand what causes it. Hope it gets resolved soon for you as well... ;-)

frederick-launoy avatar Jun 24 '24 09:06 frederick-launoy

I too am on Sonoma, M1 Pro Mac, and see high CPU utilization with Thread. I also see high CPU usage in Safari when I have a tab open to HA for an extended period (days?). Closing the HA tab in Safari immediately drops CPU utilization for the Safari process.

Coder84619 avatar Jun 25 '24 12:06 Coder84619

When running the Home Assistant Companion App on my Mac (M2 Pro), I've noticed that the app consistently uses around 10-15% of the CPU, even when not actively interacting with it. This behavior persists over an extended period and is concerning due to potential environmental impacts. As a user, I'm concerned about the long-term effects this might have on my device's performance, energy consumption, and overall health. Given that thousands of users may be running this app simultaneously, I believe it's essential to address this issue promptly.

Steps to reproduce: Install Home Assistant Companion App on Mac OS Run the app without interacting with it (e.g., no device control or automation) Monitor CPU usage using Activity Monitor or similar tools

Expected behavior: The app should not consume excessive CPU resources when idle, allowing for efficient system performance and minimizing environmental impact.

Please investigate this issue and provide a solution to ensure the app's responsible use of CPU resources and conservation of the environment.

scobby avatar Sep 26 '24 06:09 scobby

Still an issue, I didn't notice it performance-wise, but I got a notification that Home Assistant uses a significant amount of energy: image

burgerga avatar Oct 06 '24 09:10 burgerga

Same Here. HomeAssistant uses Almost as much power as a 306 Video Editing suite and More than docker (orbstack). It also gets reported to have "Significant impact on Battery Live". In the screenshot the App was already closed for About 1h.

image

I disabled the Sensors, that were updating very frequently, but still rather high Consumption.

EDIT:

So i looked through the logs again. Aparently the "Foremost App" Sensor still triggers updates in HA even though i dont have it enabled. [Info] [main] [SensorContainer.swift:223] updateSignaled(from:) > live update triggering from FrontmostAppSensor

Also there are multiple "Location update requested by user" every minute in the log. I do not have any automations, requesting updates and HA was closed on the Mac at the time of the loglines. [Info] [main] [ClientEventStore.swift:8] ClientEventStore > locationUpdate: Location update triggered by user image

joshkreud avatar Dec 02 '24 14:12 joshkreud

When I examine what is using up 100% of one of my CPU cores when the app is running it seem to be the native webframe rendering via WebKit for the Home Assistant app view. Interestingly, when I navigate away to a different view like Settings within the app it drops to single-digits, and returns to ~100% when I navigate back.

Image

This might be related or entirely separate from observed performance issues around location and sensors 🤔

mishahawthorn avatar Jan 31 '25 22:01 mishahawthorn

The work around I found is to enable "Native features only". Image

However the CPU load even in an external browser is still quite high at over 50% in a Chrome tab. So the issue likely stems from the dashboard code

Image

bytespider avatar Apr 02 '25 16:04 bytespider

I limited the number of CPU cores to 1 and reduced the max load to 30% but still seeing 40-60% CPU usage in macOS top. But the HA instance is idle. Therefore the MacMini gets very hot. A few weeks ago the CPU load was lower and the system cooler.

cbratschi avatar May 12 '25 14:05 cbratschi