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

What are the performance implications of using AltTab? #733

Closed
KerimG opened this issue Dec 15, 2020 · 3 comments
Closed

What are the performance implications of using AltTab? #733

KerimG opened this issue Dec 15, 2020 · 3 comments
Labels
support/question The author was looking for help, or didn't understand something and though it was a bug

Comments

@KerimG
Copy link

KerimG commented Dec 15, 2020

First of all, I want to say that this tool is incredible! I find the CMD+Tab of Mac OS comically lacking and am so happy to have found an open source (and even GPL licensed) solution.

What I'm wondering though is what the performance hit of AltTab looks like? With and without thumbails? I'm guessing the thumbnails are generated on the fly whenever I activate AltTab, does that really mean that it has to take a screenshot of every app and process those images?

Does "hiding thumbnails" really just hide them or does the software not generate any thumbnails? From the source code over at this line, it looks like it just completely skips generating thumbnails. I'm assuming that improves performance a lot?

I am sorry if I seem nitpicky, I am just really trying to keep additional software to fix the de/wm to a minimum.

@lwouis lwouis added the support/question The author was looking for help, or didn't understand something and though it was a bug label Dec 15, 2020
@lwouis
Copy link
Owner

lwouis commented Dec 15, 2020

Hi @KerimG! No worries, you don't sound nitpicky to me. You sound like a power user who wants to know what's under the hood, and I really enjoy this mindset! If more people were like you, Microsoft Word and Slack wouldn't take 10s to finish loading ;p

I've put in a real effort to make AltTab low impact on the system, as well as responsive when you hit the shortcut and want to see a wall of thumbnails right then and there.

Regarding background usage while the app is not showing its UI, it's subscribing to Accessibility events (e.g. "App X created a new window" or "Window X changed its title"), and other OS events (e.g. "process X was terminated", "process X was launched"). These events are very efficient. The app is basically using 0% CPU while not receiving events. When receiving events, it does very light processing. Maybe a few calls to get some Accessibility info like title of a window, or its size. It's something already contained in the event. This stuff is not expensive also. The OS expects any app to request this, so these calls are cheap. So overall you shouldn't really see any CPU use from AltTab while in the background. Memory follows the number of window you have. We store the thumbnails so that may be a few hundreds MB if you have a 4K display for instance. We store those so you get a really snappy (i.e. within a few frames) UI displayed when you press the shortcut. We then asynchronously replace these cached thumbnails with fresh ones, and cache those.

Now when you hit the shortcut, we use a private API to get the window screenshot straight from some kind of GPU buffer. I'm not well-versed enough to tell you exactly how that whole pipeline is working out, but compared to using the public API, performance is 10 folds. It's still quite expensive on large/dense displays. A 4K screen creates incredibly heavy screenshots. If you have 100 windows, each being like 20MB cause it's a 4K screen, well this is a lot of data to move around. The UX should be responsive and smooth since we show you a cached version then async update, but still we ask the OS for quite a lot of data. Again though, the private API is tapping into the WindowServer GPU buffer or something of that sort, so this data is quickly accessed.

Overall AltTab uses:

  • Basically no disk (only for storing your preferences)
  • Basically no network (only updates, if you have them set in your preferences; or if you send feedback through the form)
  • <1% in the background; and <10% "bursts" when you hit the shortcut, for a few milliseconds
  • Just enough RAM to store windows info and cached screenshots

Regarding the thumbnails, yes if you disable them, you do get to dodge all costs around them. The app would then use very little RAM, and use even less CPU when you trigger it.

I hope that shed some light. If you want to help me make it even faster/lighter, let me know! I'm always looking for help in that challenging area. Look at this PR someone shared recently for example: #705

I have to profile the app before/after before I merge this change. It could have big perf impacts.

@lwouis lwouis closed this as completed Dec 15, 2020
@KerimG
Copy link
Author

KerimG commented Dec 15, 2020

@lwouis thank you very much for the friendly and detailed answer. It's really appreciated! I am not very experienced in Swift, but I've recently come back to Mac OS after a few years of Windows and would love to learn how to create tools like AltTab for myself. Maybe it's the right time to get into Swift :)

In the meantime, can I support the project with a donation or so? I couldn't find any info on the home page.

@lwouis
Copy link
Owner

lwouis commented Dec 15, 2020

No need for donation. I'm very happy to be useful to others. Helping people is its own reward~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support/question The author was looking for help, or didn't understand something and though it was a bug
Projects
None yet
Development

No branches or pull requests

2 participants