signalapp / Signal-Desktop

A private messenger for Windows, macOS, and Linux.
https://signal.org/download
GNU Affero General Public License v3.0
14.66k stars 2.67k forks source link

unreasonably high CPU usage when idling #5444

Closed wohltat closed 1 year ago

wohltat commented 3 years ago

Bug Description

signal-desktop is constantly using around minimum 4% CPU on my computer even it is in the background and nothing is happening.

Steps to Reproduce

i just start signal-desktop via command line signal-desktop and minimize it.

Actual Result: 4%-10% or more CPU usage in idle state. This around as much or more than my window manager uses.

Expected Result: 1% or less CPU usage.

Platform Info

Signal Version: v5.7.1

Operating System: No LSB modules are available. Distributor ID: Linuxmint Description: Linux Mint 20.1 Release: 20.1 Codename: ulyssa

Linux 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Linked Device Version: Android Version: 6.0.1

strace, ltrace

profiling for 10seconds of app running

>>> sudo strace -f -p $(pgrep -x "signal-desktop" | cut -f1 -d' ' | head -1) --summary-only
strace: Process 1505438 attached with 31 threads
strace: Process 1508688 attached
^Cstrace: Process 1505438 detached
strace: Process 1505439 detached
strace: Process 1505445 detached
strace: Process 1505446 detached
strace: Process 1505449 detached
strace: Process 1505451 detached
strace: Process 1505452 detached
strace: Process 1505453 detached
strace: Process 1505454 detached
strace: Process 1505455 detached
strace: Process 1505456 detached
strace: Process 1505461 detached
strace: Process 1505464 detached
strace: Process 1505465 detached
strace: Process 1505466 detached
strace: Process 1505467 detached
strace: Process 1505468 detached
strace: Process 1505469 detached
strace: Process 1505470 detached
strace: Process 1505471 detached
strace: Process 1505473 detached
strace: Process 1505475 detached
strace: Process 1505476 detached
strace: Process 1505477 detached
strace: Process 1505478 detached
strace: Process 1505479 detached
strace: Process 1505482 detached
strace: Process 1505489 detached
strace: Process 1505499 detached
strace: Process 1505500 detached
strace: Process 1505552 detached
strace: Process 1508688 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 36,35    0,001031         515         2           restart_syscall
 35,33    0,001002         334         3           epoll_wait
  9,27    0,000263          65         4           futex
  6,42    0,000182           8        22        20 recvmsg
  4,55    0,000129         129         1           clone
  3,46    0,000098          19         5           poll
  1,73    0,000049          24         2         2 stat
  0,85    0,000024          24         1           set_robust_list
  0,53    0,000015          15         1           write
  0,35    0,000010          10         1           sendto
  0,35    0,000010          10         1           gettid
  0,25    0,000007           7         1           prctl
  0,21    0,000006           6         1           getpid
  0,21    0,000006           6         1           setpriority
  0,14    0,000004           4         1           read
------ ----------- ----------- --------- --------- ----------------
100.00    0,002836                    47        22 total

>> sudo ltrace -p $(pgrep -x "signal-desktop" | cut -f1 -d' ' | head -1) -c
^C% time     seconds  usecs/call     calls      function
------ ----------- ----------- --------- --------------------
 46.31   21.677400        7842      2764 epoll_wait
 25.65   12.007795        4144      2897 __errno_location
 16.49    7.717917        3868      1995 clock_gettime
  5.13    2.400149     1200074         2 g_main_context_iteration
  1.58    0.738548       12956        57 pthread_mutex_lock
  1.49    0.698618      349309         2 gtk_main_do_event
  1.35    0.630279      105046         6 xcb_poll_for_event
  1.16    0.541935        8884        61 pthread_mutex_unlock
  0.48    0.225044       37507         6 xcb_flush
  0.28    0.132212       22035         6 xcb_connection_has_error
  0.03    0.016099        1609        10 pthread_getspecific
  0.01    0.005189         864         6 memcpy
  0.01    0.004592        1530         3 bcmp
  0.01    0.004380        1095         4 pthread_mutex_trylock
  0.01    0.002773         924         3 __vsnprintf_chk
  0.01    0.002663         887         3 memset
  0.01    0.002573         857         3 strlen
------ ----------- ----------- --------- --------------------
100.00   46.808166                  7828 total

Most time is spend in library calls and not in syscalls. I still don't really know how to interpret this since with 4% CPU usage over 10s should be something like 0.4 seconds.

possiblerobot commented 2 years ago

Just chiming in here to say I'm seeing high CPU use, too.

Signal is consistently using around 5% CPU for me, while idling. This puts it in the top three processes for CPU use much of the time, again, while idling. Many other apps are running, including Messages.app, various web browsers, and other apps that idle with less CPU use than Signal.

This seems like a lot of CPU use for a chat app that appears to be doing nothing. I'm using an M1-based system running MacOS Monterey 12.3.1. Signal causes excess battery drain when it should be a power sipper.

Screen Shot 2022

dodiak commented 2 years ago

Lucky you,

I never go below 20% on Linux. And it lasts for months. (Several different versions tested). It looks like this problem does not have a high priority :(

On Thu, May 5, 2022 at 2:55 AM possiblerobot @.***> wrote:

Just chiming in here to say I'm seeing high CPU use, too.

Signal is consistently using around 5% CPU for me, while idling. This puts it in the top three processes for CPU use much of the time, again, while idling. Many other apps are running, including Messages.app, various web browsers, and other apps that idle with less CPU use than Signal.

This seems like a lot of CPU use for a chat app that appears to be doing nothing. I'm using an M1-based system running MacOS Monterey 12.3.1. Signal causes excess battery drain when it should be a power sipper.

[image: Screen Shot 2022] https://user-images.githubusercontent.com/38893123/166849627-841c6fc9-a3b9-46a5-91c6-6d919da9acd4.png

— Reply to this email directly, view it on GitHub https://github.com/signalapp/Signal-Desktop/issues/5444#issuecomment-1118067846, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIZB6BRVUHFRZIBDAOBSMTVIMMBPANCNFSM5BWWERWQ . You are receiving this because you commented.Message ID: @.***>

ewerybody commented 2 years ago

So is this an Electron 'disease'? I also see the Discord and Teams apps jumping into the CPU top 5 every now and then with ALL windows closed here on Windows 10. But Signal (5.43.0) seems to take quite a bite. Whereas the Telegram App (made with Qt) barely ever shows up near the top. I guess its not like plug & play to put this on Tauri, right? But would be interesting to see a comparison. 🤔

mac-linux-free commented 2 years ago

fixed in signal beta

nickma82 commented 2 years ago

I'm looking forward to it!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

scottnonnenberg-signal commented 2 years ago

We'd love an update on what CPU usage you see with the latest builds!

diaasami commented 2 years ago

I'm running signal-desktop 5.54.0 and I would say the issue seems to be resolved for me, thank you :)

wohltat commented 2 years ago

not solved for me on version v5.62.0 (linux Mint)

image

Clean start. No open chats. No open windows.


Platform Info

Signal Version: v5.62.0

Operating System: No LSB modules are available. Distributor ID: Linuxmint Description: Linux Mint 20.1 Release: 20.1 Codename: ulyssa Linux 5.4.0-126-generic #142-Ubuntu SMP Fri Aug 26 12:12:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Linked Device Version: Signal (Android): 5.52.5

habbbe commented 2 years ago

Adding my discovery to this issue:

I get a much lower idle CPU usage on version 5.60.0, but if I update to 5.61.1 I start getting around 5% CPU when idling, so something seems to have changed between these two versions. If I switch between these two versions the problem appears/disappears. 5.62.0 also exhibits the same problem.

I'm running: Arch Linux Linux 6.0.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 29 Oct 2022 14:08:39 +0000 x86_64 GNU/Linux

xlsigned commented 2 years ago

I'm currently (5.62.0) seeing 5% cpu usage on debian bullseye when idle (minimized). But my feeling is that the actual cause is somewhere deep in electron ... or in other words: There is little hope unless signal gets rid of this monster.

Updated to 5.63.1: Now at <= 1% cpu usage when idle (minimized) Maybe the electron update to 20.3.4 in 5.63.0 did something good ...

dodiak commented 2 years ago

Very similar here. But no after restart of Signal. I started to be happy a few months ago but just because after restart as well as a few hours later everything was ok. But I let my system run nonstop for several months. Few days ago I noticed again that Signal doing nothing and using 40% of one CPU core.

For me it is strange. There has been a real problem for over one year. What is Signal doing? Instead of fixing it they started to focus on removing SMS support from Signal ....

All together for me it is a strong signal to stop supporting Signal and start to look around ...

Jozef

On Thu, Nov 10, 2022 at 1:34 PM Axel Dyks @.***> wrote:

I'm currently seeing 5% cpu usage on debian bullseye when idle (minimized to tray). And this is on an AMD CPU with 8 cores = 16 threads. Which means it's almost an entire thread (90%). This is very bad! But my feeling is that the actual cause is somewhere deep in electron ... or in other words: There is little hope unless signal gets rid of this monster.

— Reply to this email directly, view it on GitHub https://github.com/signalapp/Signal-Desktop/issues/5444#issuecomment-1310217417, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIZB6BVOA6YX5VDZDZCVN3WHTTXDANCNFSM5BWWERWQ . You are receiving this because you commented.Message ID: @.***>

scottnonnenberg-signal commented 2 years ago

@xlsigned I'm glad to hear that 5.63.1 improved things for you!

@wohltat @habbbe @dodiak What are you seeing on the latest builds? Would you be interested in providing debug logs, devtools performance traces, or maybe system-level traces so we can get to the bottom of your issues?

habbbe commented 2 years ago

@scottnonnenberg-signal: Unfortunately 5.63.1 doesn't improve things on my end.

Here is a debug log from 5.60.0 (where I don't have the issue): https://debuglogs.org/desktop/5.60.0/1760593d7adc53c5f910960c53168f421ccff47ded99edd6995350095be37946.gz

And from 5.63.1 (where I have the issue): https://debuglogs.org/desktop/5.63.1/c1577ecea8b6dafb6fed9fe752ba59422d60da38b65c859f7bd9236b61444d84.gz

strace summaries (using strace --summary-only signal-desktop for exactly 60 seconds for each version). These are run on freshly linked signal-desktop instances, so no conversations were present in the list, and no messages were received while getting the traces.

strace for 5.60.0: ``` % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ------------------ 26.83 0.069925 33 2060 poll 21.59 0.056265 11253 5 wait4 18.01 0.046928 8 5330 457 futex 6.62 0.017250 3 5142 4944 recvmsg 5.46 0.014230 5 2839 mprotect 4.51 0.011753 8 1441 madvise 2.44 0.006362 4 1511 11 statx 2.30 0.005994 4 1408 read 2.25 0.005863 22 265 gettid 1.87 0.004870 12 393 write 1.36 0.003549 6 558 mmap 1.12 0.002911 4 631 217 openat 0.92 0.002388 4 535 getrandom 0.86 0.002239 4 551 epoll_wait 0.74 0.001940 10 180 sendto 0.51 0.001331 1 770 pread64 0.44 0.001141 6 175 writev 0.33 0.000869 2 406 close 0.31 0.000804 3 236 34 newfstatat 0.25 0.000652 1 373 64 access 0.24 0.000621 124 5 clone 0.12 0.000307 9 31 munmap 0.12 0.000300 3 94 fstat 0.11 0.000285 20 14 fallocate 0.09 0.000236 6 38 lseek 0.09 0.000231 1 192 117 readlink 0.09 0.000222 1 185 8 stat 0.08 0.000207 7 29 clone3 0.07 0.000184 2 80 getpid 0.04 0.000115 57 2 statfs 0.04 0.000097 2 42 fcntl 0.03 0.000086 4 20 fadvise64 0.03 0.000079 1 46 fstatfs 0.03 0.000069 0 72 rt_sigprocmask 0.02 0.000042 3 11 sendmsg 0.01 0.000038 2 16 2 unlink 0.01 0.000031 2 12 getdents64 0.01 0.000026 0 36 uname 0.01 0.000022 1 14 ftruncate 0.01 0.000019 9 2 inotify_add_watch 0.01 0.000015 3 5 connect 0.01 0.000015 1 8 eventfd2 0.00 0.000012 1 7 socket 0.00 0.000012 1 7 socketpair 0.00 0.000011 11 1 inotify_init1 0.00 0.000010 5 2 1 mkdir 0.00 0.000009 4 2 sysinfo 0.00 0.000008 0 14 prlimit64 0.00 0.000007 0 26 2 ioctl 0.00 0.000007 2 3 umask 0.00 0.000007 3 2 clock_gettime 0.00 0.000007 1 6 pipe2 0.00 0.000004 0 7 4 prctl 0.00 0.000004 2 2 epoll_create1 0.00 0.000003 0 10 dup 0.00 0.000002 0 23 rt_sigaction 0.00 0.000002 1 2 1 arch_prctl 0.00 0.000002 2 1 set_tid_address 0.00 0.000002 0 3 epoll_ctl 0.00 0.000002 2 1 set_robust_list 0.00 0.000002 2 1 rseq 0.00 0.000001 0 4 getsockname 0.00 0.000001 0 9 getgid 0.00 0.000001 1 1 epoll_create 0.00 0.000001 1 1 clock_nanosleep 0.00 0.000000 0 1 brk 0.00 0.000000 0 2 rt_sigreturn 0.00 0.000000 0 17 1 recvfrom 0.00 0.000000 0 2 shutdown 0.00 0.000000 0 1 bind 0.00 0.000000 0 1 listen 0.00 0.000000 0 2 getpeername 0.00 0.000000 0 2 setsockopt 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 getcwd 0.00 0.000000 0 4 symlink 0.00 0.000000 0 10 getuid 0.00 0.000000 0 11 geteuid 0.00 0.000000 0 9 getegid 0.00 0.000000 0 4 getresuid 0.00 0.000000 0 4 getresgid 0.00 0.000000 0 1 getpriority 0.00 0.000000 0 1 sched_getaffinity 0.00 0.000000 0 2 dup3 0.00 0.000000 0 1 sched_setattr 0.00 0.000000 0 1 sched_getattr 0.00 0.000000 0 1 1 pkey_alloc ------ ----------- ----------- --------- --------- ------------------ 100.00 0.260628 10 25977 5864 total ```
strace for 5.63.1 ``` % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ------------------ 27.08 0.100824 5 19991 493 futex 24.88 0.092637 30 2992 poll 14.95 0.055651 11130 5 wait4 8.54 0.031787 4 6767 6570 recvmsg 4.69 0.017465 5 3261 mprotect 2.91 0.010839 19 563 getrandom 2.74 0.010201 3 2998 read 2.37 0.008836 5 1515 madvise 1.91 0.007097 4 1524 11 statx 1.64 0.006095 3 1913 write 1.32 0.004908 8 572 mmap 1.03 0.003829 21 177 writev 1.01 0.003756 14 262 sendto 0.75 0.002789 464 6 pipe2 0.66 0.002460 3 659 217 openat 0.61 0.002282 456 5 clone 0.52 0.001944 0 1955 epoll_wait 0.51 0.001895 105 18 fallocate 0.28 0.001045 33 31 clone3 0.23 0.000869 1 438 close 0.21 0.000780 3 242 34 newfstatat 0.17 0.000646 8 76 rt_sigprocmask 0.17 0.000638 0 890 pread64 0.13 0.000472 16 29 munmap 0.12 0.000449 1 264 gettid 0.11 0.000420 3 134 fstat 0.08 0.000293 10 29 sendmsg 0.05 0.000188 0 374 64 access 0.05 0.000168 4 42 lseek 0.04 0.000155 7 20 2 unlink 0.04 0.000132 0 192 117 readlink 0.03 0.000114 2 53 fcntl 0.03 0.000100 1 87 getpid 0.02 0.000089 4 18 ftruncate 0.02 0.000077 11 7 socketpair 0.02 0.000065 5 11 geteuid 0.01 0.000052 1 36 uname 0.01 0.000046 0 185 8 stat 0.01 0.000029 1 23 rt_sigaction 0.01 0.000027 13 2 statfs 0.01 0.000026 2 12 getdents64 0.00 0.000015 2 7 4 prctl 0.00 0.000015 0 20 fadvise64 0.00 0.000015 1 14 prlimit64 0.00 0.000013 6 2 inotify_add_watch 0.00 0.000010 0 34 recvfrom 0.00 0.000009 0 46 fstatfs 0.00 0.000009 9 1 inotify_init1 0.00 0.000007 1 4 dup 0.00 0.000006 3 2 setsockopt 0.00 0.000006 2 3 epoll_ctl 0.00 0.000005 2 2 shutdown 0.00 0.000005 5 1 getpriority 0.00 0.000004 0 5 connect 0.00 0.000004 0 13 getuid 0.00 0.000004 0 9 getgid 0.00 0.000004 1 4 getresuid 0.00 0.000004 1 4 getresgid 0.00 0.000003 0 7 socket 0.00 0.000003 3 1 epoll_create 0.00 0.000003 3 1 clock_nanosleep 0.00 0.000003 0 8 eventfd2 0.00 0.000002 1 2 sysinfo 0.00 0.000002 1 2 epoll_create1 0.00 0.000001 0 2 rt_sigreturn 0.00 0.000001 0 3 2 mkdir 0.00 0.000001 0 2 1 arch_prctl 0.00 0.000001 1 1 set_tid_address 0.00 0.000001 1 1 set_robust_list 0.00 0.000001 1 1 sched_setattr 0.00 0.000001 1 1 1 pkey_alloc 0.00 0.000001 1 1 rseq 0.00 0.000000 0 1 brk 0.00 0.000000 0 26 2 ioctl 0.00 0.000000 0 1 bind 0.00 0.000000 0 1 listen 0.00 0.000000 0 4 getsockname 0.00 0.000000 0 2 getpeername 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 getcwd 0.00 0.000000 0 4 symlink 0.00 0.000000 0 3 umask 0.00 0.000000 0 9 getegid 0.00 0.000000 0 1 sched_getaffinity 0.00 0.000000 0 2 clock_gettime 0.00 0.000000 0 2 dup3 0.00 0.000000 0 1 sched_getattr ------ ----------- ----------- --------- --------- ------------------ 100.00 0.372334 7 48641 7526 total ```

The futex syscall seems to be an obvious outlier.

Let me know if there is any other specific information I can provide!

serakeri commented 2 years ago

So is this an Electron 'disease'? I also see the Discord and Teams apps jumping into the CPU top 5 every now and then with ALL windows closed here on Windows 10.

I'm seeing a similar problem with Electron apps. On macOS the process "Signal Helper (Renderer)" idles at 3% with all windows closed and "Discord Helper (Renderer)" also idles at 3% with all windows closed.

edit: This was observed on macOS 11.7.1 using Signal 5.63.1

I tried building Signal with the latest versions of Electron 21.3.0 and 22.0.0-beta.6 but the issue was still there. However I am not seeing this issue when using the electron app "Electron Fiddle". The "Electron Fiddle Helper (Renderer)" idles at 0% with the window open, but I'm not certain if the issue is with a part of electron or with how it is being used.

indutny-signal commented 1 year ago

@habbbe we just released a new beta version (v6.0.0-beta.1). Could you try installing it and running the binary with --enable-gpu flag? I'm hoping that it might improve idle CPU usage for you. Please let me know if not!

habbbe commented 1 year ago

@indutny-signal I tried the v6.0.0-beta.2, but it still gave me the same idle CPU usage. Adding or removing the --enable-gpu flag did not change the outcome.

therentabrain commented 1 year ago

I don't know whether this is for sure related, but I err on the side of not opening a new issue :) I am using 6.0.1 on Windows 10 with a very nice Ryzen 9 processor and lots of RAM etc. Correct me if I'm wrong, but prior to 6.x, I think Signal only ran one Signal.exe process. Now it seems to run five of them. Some are below normal priority, I think one is normal, and one is Above normal. (I see Zoom doing the same sort of thing; is there a common reason?)

If I leave the priorities set that way, the rest of my system slows down a little. But more importantly, my OBS, which is often running a stream for a large audience with an Above Normal priority single process, begins to glitch.

Even with Signal totally idle, nothing really happening, my livestream begins to choke up and I am dropping hundreds of frames. CPU usage still shows as under 10%, and resource meters show everything I can think of is 2%-50% utilized; nothing above that. OBS is set to use a different GPU than Signal for rendering, but nonetheless, rendering is stuttery.

I find if I then do this: wmic process where name="signal.exe" call setpriority "64" The problem totally goes away. (That command sets all Signal.exe processes to Low priority.)

After that, OBS works perfectly, 0 dropped frames, and Signal seems totally responsive and perfectly usable for sending/receiving texts. No perceivable difference in performance, but OBS is now happy.

What in the living.

Thanks, by the way. I do love Signal and use it all the time.

lnicola commented 1 year ago

Correct me if I'm wrong, but prior to 6.x, I think Signal only ran one Signal.exe process.

It didn't. This is usual for Chromium and Electron apps, and not something bad in itself.

therentabrain commented 1 year ago

I guess I never noticed. Thanks for the correction :)

dodiak commented 1 year ago

OK,

few days waiting and it's again here. Signal Desktop is doing nothing and 15-18% of CPU. https://debuglogs.org/desktop/5.63.0/e42aff75b6c08663816d7726c1e07ebbde7c447b81c246a01fc0c7f9288fdfa4.gz

On Wed, Dec 7, 2022 at 1:38 PM therentabrain @.***> wrote:

I guess I never noticed. Thanks for the correction :)

— Reply to this email directly, view it on GitHub https://github.com/signalapp/Signal-Desktop/issues/5444#issuecomment-1340907111, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIZB6EOP6WMSYBBLHXC5IDWMCALDANCNFSM5BWWERWQ . You are receiving this because you were mentioned.Message ID: @.***>

mac-linux-free commented 1 year ago

This is somehow solved for me. Version 6.0.1 just 3-4% idle.

dodiak commented 1 year ago

ok, thanks, sorry. I am still on the old version. Upgrading ....

On Fri, Dec 9, 2022 at 11:11 AM mac-linux-free @.***> wrote:

This is somehow solved for me. Version 6.0.1 just 3-4% idle.

— Reply to this email directly, view it on GitHub https://github.com/signalapp/Signal-Desktop/issues/5444#issuecomment-1344110390, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIZB6FMMUW2YWOEPM7KZCDWMMAU7ANCNFSM5BWWERWQ . You are receiving this because you were mentioned.Message ID: @.***>

habbbe commented 1 year ago

Just reporting in that I'm still seeing 4-6% CPU when idle with 6.1.0.

indutny-signal commented 1 year ago

This is still on our radar and we are trying to figure out what's going on. If y'all could send additional debug logs, that'd be very appreciated!

Could anyone on this thread try running profiler on it? I think perf is the recommended tool for it nowadays?

If someone here is on macOS - could you try profiling it using CPU Profiler in the Instruments.app that comes with Xcode?

Sorry, I know I'm asking for lots of details, but what we need to make progress on this is information!

Thanks!

janvlug commented 1 year ago

See also issue #4459.

habbbe commented 1 year ago

I can report that I'm seeing very low CPU usage (0-0.5%) when idling now. I could only test this back to 6.6.0, but the same is true for 6.8.0.

For me this seems to be solved!

Ra72xx commented 1 year ago

Same here, Ubuntu 22.10. Very low CPU usage now.

sylv-io commented 1 year ago

Same here on Arch Linux.

chronos000 commented 1 year ago

Same here. Low CPU usage (less than 1%, where I could see more than 10% before) Pop!_OS 22.04 Signal 6.7.0, installed via flatpak

scottnonnenberg-signal commented 1 year ago

Thanks for all your reports, everyone. I'm going to close this.

Future folks: Please enter a new bug if you see this behavior again.