r/AskProgramming • u/SandwichForLunch • 2d ago
Why don't browsers have "Pause" features to limit RAM usage?
Situation / Background Info (if TL;DR skip to the actual question at the bottom):
I'm currently playing a CRPG (Pathfinder: Kingmaker, just think of Baldur's Gate 3 if you're unfamiliar) which, for an optimization-inclined player such as myself who is not super familiar with the mechanics, requires a LOT of open Wiki pages to see how things work and what skills/spells/items/etc do. I go back to reference many of these pages occasionally, so it's easiest to keep them open.
At times I also have Youtube open, I'm sometimes taking a break and browsing other stuff, or even letting something download in the background while I play.
I think to myself:
Right now I have 8 wiki/guide tabs open, and that's after closing over 10 others, ones which I don't have to check as frequently. I also have 6 other tabs open unrelated to the game, most of which I only touch once a day or even once every couple of days.
Why the heck does my Internet Browser take up 5+ GB of my RAM, just to "hold" these pages in the background? And when I do check on them, I don't require to actually do anything advanced? They might as well be a large screenshot for my purposes.
I googled and found this answer:
https://www.reddit.com/r/AskProgramming/comments/s8ogk6/how_do_browsers_use_so_much_ram/
If I understand correctly, the short of it is that each tab runs its own instance of an engine for various purposes. That much makes sense.
The first available (lacking) solution:
I use OperaGX, which at least in its advertising seemed to be very proud of its "RAM Limiter" feature. All it does is give you a slider where you can limit your RAM usage for the browser - essentially I can set the slider to [X] GB and it will only ever take up [X] GB at a time.
Why it is lacking:
As far as I can tell, if I set the limit to, say, 1 GB, there is no differentiation between what I care or don't care about. Maybe my youtube video will be affected all the same, resulting in stuttering or being unable to play at all. Maybe that download I'm doing in the background will be affected.
The other available solution:
I did a little googling on "Tab Suspender" extensions, which claim to reduce memory usage by hibernating tabs you haven't used in some amount of time. It's not my perfect solution, as I don't even care to have the tabs run all their garbage even when I AM accessing the page, but maybe it's good enough.
I find "The Great Suspender Reloaded" which seems to be the #1 recommendation (or at least, the original Great Suspender was...), go to download it, and OperaGX pops up with a warning window:
"This extension's contents have not been verified by Opera"
"It can: Read and change all your data on all websites."
"It can: Read and change your browsing history on all your signed-in devices."
Well if that's not the biggest red flag I've ever seen, I don't know what is. I ain't touching that.
-----------------------------------
Anyways, my preferred solution:
Have a way to "pause" a tab by "converting" a page into a simple screenshot. You click a button, the browser automatically takes a screenshot of the page, and displays it as such. All other memory or CPU requirements are killed. I don't need each of my 20 wiki pages to constantly be running muted videos/ads when I access them (and maybe even in the background? I wouldn't put it past them), I just need them to display text and look as pretty as they did when I first loaded them. If I want to access the actual page again, I can just hit the "reload" button and it reloads the actual web page again.
Quirks:
I imagine this wouldn't be very compatible with resizing the browser window. I don't care. If I care, I can reload & pause it again at the new size.
Maybe we'd still want page links to work, so even on a "paused"/"screenshotted" page I can still click a link and then the next page is accessed as normal. I'm sure this would be extremely easy to implement - if adblockers can detect specifically ads and block them, I'm sure this "pause" feature can detect text/image links and overlay clickable zones onto a PNG.
Maybe this could conflict with logins? But I highly doubt that, and even if so, I'm the one choosing to pause the page - I'll relog if I have to when I get back to the real website.
Questions:
Is this unfeasible for some reason?
Does something like this exist and I'm just ignorant?
Why doesn't every browser include this kind of thing as a baseline option? Is the use case too narrow? Are the browser companies too symbiotic with sneaky advertising to allow for this?
Thanks!
2
u/shapergang1 2d ago
Browser already has tab sleeping built in. You do not need a screenshot hack for that.
30
u/the-liquidian 2d ago
Browsers already do something similar to pausing. They suspended background tasks to reduce CPU usage, memory consumption and battery drain.
21
u/aioeu 2d ago edited 2d ago
Firefox, at the very least, already automatically unloads unused tabs if the system's available memory is low (or more specifically when memory pressure is high).
I would expect other browsers to have something similar.
5
u/Kaldaien2 2d ago
They DO. They can suspend tabs, same as mobile phones do.
Instead of keeping resources resident, or even paged to disk, it will be outright killed and simply refresh the page upon reactivation... this is not default behavior since a refresh is destructive, but when memory constrained they will resort to this.
Your screenshot idea is flawed since unless the resources remain loaded then upon restore the page contents will not match the proxy screenshot.
1
u/rustprogram 2d ago
you say we want this but at least I don't want this, at least not by default. when I go on YouTube to listen to music for example, I don't want the music to stop as soon as I switch to another tab. this background tab process that plays music also needs some ram memory
2
u/Doug2825 2d ago
You are looking for reader mode and/or content blockers that can be configured block certain types of content i.e. video, javascript.
2
u/arelath 2d ago
You can set both chrome and edge to use a single process, which saves a ton of memory because you don't need a new chrome instance for every tab or window. It's called single process mode, but it's not really recommended because it reduces stability and security (basically the reasons for this complicated architecture).
Sleeping tabs, which I thought was automatic, pauses non-visible tabs and frees the resources they use. I don't think you can force this to happen though.
2
u/DT-Sodium 1d ago
... this again and again. Windows processes hold RAM because they can, so the task can be quickly be resumed if needed. If the OS actually requires RAM for a task, it will reclaim it back.
1
u/Uncontrollably_Happy 2d ago
If you were to implement this, you’d want to pause JavaScript, pause all the workers and threads, cancel any inflight queries, pause video and audio, maybe some other things as well. All of this can be done programmatically. Conversely you can resume all of these things. Some webapps might break because they’re not designed to be paused.
Pausing all these things would essentially pause memory usage and stop cpu usage. There might still be a little cpu usage, but memory shouldn’t increase.
This could probably be implemented as a browser extension. It’s possible one exists.
1
u/edave64 2d ago edited 2d ago
"It can: Read and change all your data on all websites." kindof makes sense, since it needs to replace all the tab contents with the suspend page.
There are browsers that can do this. E.g. in Firefox and it's derivatives you can "Unload" a tab, throwing it out and forcing the page to reload when you enter the tab again. I think it can also do that automatically with pages in the background.
Brave has a "Memory Saver" that I think does the same thing.
Safari and Orion have an energy saver mode that suspends background tabs.
The primary issue is that the browser has no way of asking a page if it has any unsaved data. So if it were to just evict the page, the user might lose data. I know that Orion has thrown away things I'm typing multiple times :/