leggett / simplify

Issue tracker for Simplify Gmail, a browser extension to simplify Gmail's interface
https://simpl.fyi
1.64k stars 103 forks source link

High memory usage in Safari #513

Closed DonutEspresso closed 3 years ago

DonutEspresso commented 3 years ago

Congrats on the new release! Really liking a bunch of the new options that are now available.

I've noticed that in Safari CPU usage seems to be much higher than it was with v1. Specifically on the thread view/reply pane, it bogs down so much that there's a significant delay between keystrokes and text appearing on the screen. It also triggers Safari's This page is using significant memory... banner. It gets better if you move back to the inbox view, or if you turn off Simplify entirely. I'm not sure if other views are impacted, but this makes v2 untenable for Safari in its current form.

Happy to provide more info or context if needed.

Safari 16610.4.3.1.4 MacOS 11.2.1

leggett commented 3 years ago

I've seen this myself when I was debugging and had the developer console open (which sucks down a lot of resources) but never when I have that closed. I will switch back to Safari for a few days and see if I have any issues.

I assume that you used Simplify v1 on another browser (v1 never worked on Safari)?

A few other questions:

DonutEspresso commented 3 years ago

I assume that you used Simplify v1 on another browser (v1 never worked on Safari)?

Y'know that's a good question - I've been using it for about a month or so on Safari so maybe it was always v2, just an earlier version? I might have conflated it with v2 when the new messaging/onboarding started rolling out. It was OK before the new onboarding rolled out.

Do you use offline?

Safari doesn't appear to support offline, so I think that's a no.

Do you use the default tabbed inbox?

Yes.

leggett commented 3 years ago

I released Simplify v2 quietly on Safari about a month ago, so you've been using v2 all along.

I've done a pretty extensive audit and I think this is just Gmail. I've seen it as high as >2GB of memory if I leave the tab open all day. :( I'm going to keep looking though. I want Simplify to have as small an impact on memory and CPU as possible.

Screen Shot 2021-02-13 at 3 18 51 PM
leggett commented 3 years ago

It is possible some of Simplify's memory/cpu usage is under the "mail.google.com" item since it injects css and js into Gmail. But then why would it have its own entry? ¯_(ツ)_/¯

And the difference with Simplify enabled/disabled isn't that large (if any at all). I looked at things in the Chrome Task Manager too and the memory/cpu footprint appears to be the same with Simplify on/off. Also, interestingly, Gmail uses WAY less memory in Chrome in a fresh tab: 175 MB vs over 1GB in Safari.

Screen Shot 2021-02-13 at 3 40 42 PM

I also used the performance tools built into Chrome and wrote some separate tests to see how MutationObservers are destroyed in various places. Didn't find any big leaks or memory hogs.

leggett commented 3 years ago

One last thing I tried... I removed ALL the javascript and left only the CSS in Simplify and tried it again in Safari and Chrome. Same memory footprint and CPU usage. So I really don't think it is Simplify causing the problem.

Let me know if you have any suggestions as to things to look for or tools to use to profile things.

Screen Shot 2021-02-13 at 3 54 58 PM
DonutEspresso commented 3 years ago

Hey @leggett - thanks for digging into this! This is indeed strange. I've got a few other extensions so maybe something else is wreaking havoc with Simplify. I'll dig some more and report back if I find anything.

leggett commented 3 years ago

I went one step further on this and reached out to DebugBear, a company that analyzes the performance of websites and extensions. Their response:

Thanks for sending over the updated code. I've taken a look and didn't notice any performance issues being introduced. The extension looks well-built, and I don't see how I could help improve it.

Like you, I wasn't able to identify any code slowing down the initial load. Memory usage seems to go up 20MB (plus 17MB for the background page), but Gmail is around ~300MB for me anyway.

leggett commented 3 years ago

New idea: not sure if this applies or not and I don't see how this could actually cause a big issue, but if you don't use the reading pane at all, turn it off entirely under Gmail Settings > Inbox > Reading pane.

I'm still digging but I've found a couple places where I am re-detecting things needlessly when reading pane is enabled and set to No Split Pane. There is no waste if you use Vertical or Horizontal split – only if you have it enabled and set to No Split. It shouldn't cause an issue but maybe.

DonutEspresso commented 3 years ago

Sorry for the radio silence on this. I turned Simplify back on again this week and oddly was unable to repro the original problem! I played with a couple of different options but everything seems... ok now?! I'm sorry for the noise this might have created.

Just wanted to share that I really appreciated your pro-activeness on this issue. Gives me a ton of confidence to support the product longer term. Thank you! 🙏

leggett commented 3 years ago

Thanks Alex. I'm still not 100% convinced something isn't amiss. Memory usage under activity monitor for mail.google.com does seem higher with Simplify enabled. It makes no sense to me as (1) I don't see the same issue in other browsers and (2) this appears to happen even if I remove ALL the javascript. But I don't think it is nothing.

I've fallen down the rabbit hole and am basically doing a line-by-line code review of the entire code base. It is something I had on my list to do and I had been putting it off. This was the kick in the pants I needed. I haven't found anything huge but there have been small improvements to be made.

Once I'm done and am confident Simplify isn't the culprit, I plan to try and reach out to Apple. I've found a couple other bugs with Safari's new support for Web Extensions and I wonder if there is something on their end.

leggett commented 3 years ago

I reached out to Morten Just (we crossed paths in a former job) to see if he had any thoughts on this given he was digging into comparing Safari vs Chrome's memory usage with Gmail running.

He sent back the following:

I just tried that with and without Simplify. Charts attached are still WIP and not super clear, but I think I'm seeing what you're describing: the RAM usage goes up before I launch Gmail. But in the end, both sessions seem to use more or less the same amount. Not sure why that is. It's tempting to think Safari actually loads Gmail when it sees the extension.

Screen Shot 2021-02-27 at 11 35 05 PM