Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High RAM usage from replayd system daemon when thumbnails are enabled #4194

Open
filipe-aparicio opened this issue Feb 4, 2025 · 30 comments
Labels
performance unactionable Further action is not possible due to lack of information or support

Comments

@filipe-aparicio
Copy link

I recently noticed my RAM usage increase drastically when using AltTab and after some inspection and testing, figured out that it was due to having thumbnails enabled.
After a few hours of enabling thumbnails, the replayd system process that handles screen capturing, went from using 9.7MB of RAM to >2GB. Force quitting replayd temporarily fixes the issues, but a few hours later, the RAM usage gets back to a couple of GBs.

If I disable the thumbnails and remove the screen recording permissions, replayd usage stops completely, which can be seen in the system logs using the following bash command:
log show --predicate 'process == "replayd"' --info --last 1h

As soon as re-enable the screen recording permissions and thumbnails, replayd starts producing thousands of logs in just a few minutes. A few hours later, the RAM usage starts increasing drastically again.

Im not sure if this is a bug, a memory leak, or just a side-effect of how MacOS handles the screen recording requirements for AltTab to work.

Just wanted to share this in case it's a bug that can be fixed.

@lwouis
Copy link
Owner

lwouis commented Feb 4, 2025

Hi,

Thank you for sharing this.

I'm afraid these are macOS internals we have no agency over. AltTab retrieves screenshots of windows, so it can show thumbnails of them. We need to screenshot often since the user needs the thumbnail to be fresh to reflect the windows.

I looked at replayd on my machine, and indeed if I press alt+tab a few times, I see the RAM increase. It went from 16MB to 25MB perhaps. However, as I typed this message, I could see the RAM go back down to 18MB.

Perhaps there was a memory-leak on some version of macOS, that's been fixed on my version (15.2 (24C101))? Which macOS version are you on?

Thank you

@filipe-aparicio
Copy link
Author

Hi @lwouis,

I was on 15.2 when I first detected this. I've recently updated to 15.3, and re-enabled the thumbnails to see if the behavior changes.

I noticed that the RAM increase is lower, but still happening. For example, my replayd process is currently sitting at 89.7MB, but slowly increasing with time - it doesn't seem to go down at all.

I've also restarted my machine a couple of times to see if that helped, but nothing changed.

I'm sure this is related to AltTab because when the thumbnails are disabled, replayd's memory usage is barely any.

I can leave the thumbnails on for a few days and see how the RAM usage changes over time.

I'm not sure if other users are experiencing this, but many will probably not make the connection between replayd and AltTab, thinking it's just a random MacOS process.

If there's any specific testing I could do, or logs you might find helpful, please let me know!

@lwouis
Copy link
Owner

lwouis commented Feb 4, 2025

Hi,

Thank you for your message.

I've been reworking thumbnails recently. I don't think it would impact this macos internal memory leak, but it doesn't hurt to try.

Could you please try out this local build and let me know?

Thank you 🙇

@filipe-aparicio
Copy link
Author

@lwouis I just installed the build. I'll provide feedback in a day or two!

@filipe-aparicio
Copy link
Author

@lwouis, the build you provided crashes frequently. Is the App saving logs anywhere in case you want to take a look?

@lwouis
Copy link
Owner

lwouis commented Feb 5, 2025

Oh that's not good! Could you please open the app from Terminal.app: /Applications/AltTab.app/Contents/MacOS/AltTab --logs=debug

Thank you

@lwouis
Copy link
Owner

lwouis commented Feb 5, 2025

I'm ready to release a big update with many improvement. However this crashing on your setup is worrying me. I'll wait on your feedback before releasing anything 🙇

Here's the latest build

@filipe-aparicio
Copy link
Author

@lwouis I'm testing it now and will share the logs in a few hours ✌️

@filipe-aparicio
Copy link
Author

@lwouis, using the latest build you shared, there is a bug with the permissions, where it keeps saying that Accessibility isn't allowed, despite already having the permission set:

Image

The pop-up only appears when I run /Applications/AltTab.app/Contents/MacOS/AltTab --logs=debug

Launching AltTab normally, the permissions pop-up does not appear, and I can switch and focus on windows normally, meaning that Accessibility permission is working. Eventually the app crashes.

I'm going to try a clean install, and see if that helps.

@filipe-aparicio
Copy link
Author

filipe-aparicio commented Feb 6, 2025

@lwouis, I performed a clean install (removed the app, reset the permissions, deleted all folders and files related to AltTab, restarted MacOS), and I keep getting the same Accessibility permission error when running the debug logs.

Here are all the files that I removed before performing a new installation:
Image

EDIT 1: The app keeps crashing after a few minutes.

EDIT 2: Performed a clean install of the latest public release (v7.19.1) and the crashes stopped. But If I try to run the logs script, I still get the same Accessibility permissions error that I shared in my previous comment. In this situation, the app crashes and I have to manually kill the process to be able to use AltTab again.

@lwouis
Copy link
Owner

lwouis commented Feb 6, 2025

Hey @filipe-aparicio,

When running the app through the Terminal, macOS needs permission to be granted to the Terminal, since it's the parent process.

On your screenshot, I marked it with a blue arrow on the bottom right:

Image

@lwouis lwouis mentioned this issue Feb 12, 2025
@lwouis
Copy link
Owner

lwouis commented Feb 12, 2025

Hi @filipe-aparicio,

I'm holding to many improvements that I'd like to release. My only concern is the crashes you reported previously. Other people in other tickets I've fixed didn't have the issue.

Here's the build I'd like to release. Could you please let me know if it works on your machine without crashing?

Thank you 🙇

@lwouis
Copy link
Owner

lwouis commented Feb 12, 2025

Update: please use this build instead

@filipe-aparicio
Copy link
Author

@lwouis sorry I was busy for the past couple of days. I'll test this today and let you know later the results.

@lwouis
Copy link
Owner

lwouis commented Feb 16, 2025

Hi @filipe-aparicio,
Could you please try out the build?
Thank you 🙇

@ngocphamm
Copy link

ngocphamm commented Feb 18, 2025

I was going to ask if there's some reported issues with memory usage, as AltTab itself is using almost 300MB on mine.

Image

Then I check this issue out and notice replayd is also using a lot of memory too. Almost 1GB now. I didn't really pay attention to this, so I can't say this happens recently or not.

EDIT: Forgot to mention, I'm using AltTab 7.19.1, on macOS 15.3.1.

And this is right after restarting AltTab. Is this normal amount of memory being used?

Image

@lwouis
Copy link
Owner

lwouis commented Feb 18, 2025

Hi everyone,

I'd like to release the new version. It contains lots of big improvements: compatibility with Stage Manager, higher resolution thumbnails, detecting windows on other Spaces from launch, performance improvements, better focus, improved localizations, bug fixes, etc.

Before I released, could everyone please help QA this build?

If it's working for everyone, I'll release it 🚀

Thank you 🙇

@ngocphamm
Copy link

@lwouis Running this and killed replayd so it starts at ~7MB of memory now.

I notice a slight lag sometimes when I first hit Alt + Tab and the list of windows show up, and I use the mouse cursor to hover between windows. Sometimes it takes a little bit to catch up with my quick movement of the mouse. After a few times like that, it seems to be faster, almost immediately response, highlighting the window thumbnail as I put the mouse cursor over it.

And it seems to be always like that after I switch back and forth between my spaces (I have some app opens in fullscreen mode taking up another space).

@filipe-aparicio
Copy link
Author

@lwouis, I've been running this new build for a few hours now and everything seems to be working fine (no crashes). I also started running the app in debug mode through the terminal and the logs seem normal, without any errors popping-up.

It's a bit early to assess the replayd RAM usage yet, but I've restarted the process and it has been consistently hovering between 7-10 MB, which seems to be a good sign! I also noticed that unlike the stable release on my machine, the RAM usage does decrease from time to time when I stop switching between windows.

I don't get any lag whatsoever switching windows, and the thumbnail resolution seems to be adapting better to external displays when compared with the stable release.

If anything changes, I'll let you know.

@ngocphamm
Copy link

Here my replayd is still increasing its memory usagge over time, even though doesn't seem like a lot. I do have some other apps with screen recording permission, so I'm not sure if it's other apps or not.

Image

Image

@filipe-aparicio
Copy link
Author

Yeah, the RAM issue is still there as well. replayd is currently sitting at around 250 MB and going up. My temporary fix is to occasionally kill the process so it can get back to manageable values.

@ngocphamm on my machine, if I stop AltTab from running (or disable the thumbnails) and restart replayd, the RAM usage goes back to normal (around 10-20 MB), and stays that way indefinitely. As soon as I start using AltTab again, a few hours in, the RAM usage coming from replayd starts going up again, occasionally going over 2.5 GB. You can try that on your machine to confirm if the behavior is similar.

@lwouis
Copy link
Owner

lwouis commented Feb 19, 2025

Hi,

Since I can't reproduce this issue on my machine, I think it's likely not an issue with AltTab.

Perhaps a macOS bug that only triggers in some cases? Perhaps an interaction with another app? Perhaps an antivirus or JAMF-type software?

I'm afraid that without anything else to work off of, I'll have to close this issue

Thank you

@lwouis lwouis added unactionable Further action is not possible due to lack of information or support performance labels Feb 19, 2025
@filipe-aparicio
Copy link
Author

filipe-aparicio commented Feb 19, 2025

@lwouis, since I started testing this build, I've had 2 crashes. I couldn't get logs for the first one as I wasn't running the app via the terminal, but I was able to collect logs from the second crash.

These are the last entries before crashing:

Image

@lwouis
Copy link
Owner

lwouis commented Feb 19, 2025

Thank you for sharing this @filipe-aparicio!

I think the issue is with mapping the Space of a window. It seems there is a window and we can't map its Space. This happens after a Screen Change event, so I guess the window is moved to another Space after plugging/unplugging a monitor, and we don't know about that Space yet?

Could you please try out this build? Does it work when you trigger the screen event shown in your screenshot?

Thank you

@ngocphamm
Copy link

AltTab (the build from yesterday) has crash twice on mine so far. I have sent the report both times after starting the app again. Hopefully that provides some insights into the issue.

I will try the build from today now.

Meanwhile, replayd keeps climbing on memory usage too.

@filipe-aparicio
Copy link
Author

@lwouis, this build still crashes. I have 2 external monitors connected via a dock - not sure if that could be contributing to the issue. I'll try running the build via the terminal again to capture any useful logs and send them later today.

@lwouis
Copy link
Owner

lwouis commented Feb 20, 2025

Thank you @filipe-aparicio

I release a fix. Does the latest public release work for you?
I made a fix so that it doesn't crash. It's a bit of a hotfix. I should now work on a better fix. I just wanted to stop having people crash. It's a bad experience 🙇‍♂️

If it still crashes for you, could you please share the logs?
Thank you!

@ngocphamm
Copy link

@lwouis I'm on the latest public release version, and I just got a crash. Clicked to send the report.

@lwouis
Copy link
Owner

lwouis commented Feb 23, 2025

Thank you @ngocphamm

I found some crash reports on v7.20.1 on AppCenter. I think one of those is yours. It points to a crash in: closure #1 () throws -> () in AltTab.Application.manuallyUpdateWindows() -> () AXUIElement.swift:207. Unfortunately, I don't see what could go wrong except perhaps a conditional unwrapping failing.

Could you please try to reproduce the crash with this build, and let me know if it's gone?

Thank you 🙇

@ngocphamm
Copy link

@lwouis Sorry I'm not going to be able to test this for a few days and I'm away from the computer that had the crashes. I will when I'm back! Thanks for fixing those issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance unactionable Further action is not possible due to lack of information or support
Projects
None yet
Development

No branches or pull requests

3 participants