Ask HN: One tab on Chrome takes about 100MB memory, why?
with say 30 tabs open, 3+ GB is gone, chrome is such a dominant memory consumer! in fact it takes about 10X more memory than everything else combined on my ubuntu all the time, why?
Yes I use onetab extensions etc to save memory, just wondering why one tab takes so much memory, is this a design fault?
209 comments
[ 3.9 ms ] story [ 200 ms ] threadFor my part, whenever my computer is slow, browsers are almost always the cause. I typically restart one or both of my browsers (Chrome/Firefox) when my computer is slow or the fan is whirring like crazy.
If the question really needs answering, the poster should just get a heap profile. Some instructions are here: http://goog-perftools.sourceforge.net/doc/heap_profiler.html
You may also wish to try the memlog flag to chrome, or rebuild chrome with TCMALLOC_SMALL_BUT_SLOW defined. Warning: it does what it says.
This is exactly the attitude that leads to such problems. Applications that assume they can use all of the available memory on the machine are hostile to multitasking environments.
If you have very little, it will turn off many optimizations, turn on features that reduce memory (like tab suspension built into the browser), and overall adjust the whole browser to use less resources but go slower.
Entirely unused RAM is a waste if never used.
Not the applications.
Caching the output of computation was incredibly valuable to our customers, and the caching that the OS would have done would have had little to no benefit to our customers.
The same could be said for Chrome. Maybe there is value to a globally coordinated OS caching manager, but the OS shouldn't have sole responsibility for caching. Such an approach is clearly suboptimal for the user in at least one use-case (see example above).
Chrome has to cooperatively share resources with other applications and with aggressive caching at application level, the only strategy at hands of the OS is to start swapping.
Applied absolutely, it results in deeply sub-optimal behavior in a large number of cases.
Another case could be image decode caching via glide for scrolling lists, or skia output tile caching in a browser, or texture caching in a game engine, or reference frame caching in a video decoder, or glyph caching in a word processor, or block caching in a constructive solid modeller, or result caching in a spreadsheet, or composition caching in a presentation tool, etc. etc. etc.
Caching is an enormously effective tool for applications and operating systems. If an operating system removed it as a tool for applications, it wouldn't likely be a competitive operating system.
Should applications abusively and single-mindedly monopolize memory usage? In some cases, maybe. In general, I think we'd tend to be on the same side of things. I like to see well-behaved applications (that make conservative and efficient use of system resources) and robustly managed operating systems (that don't let apps walk all over them).
Shaming such RAM hogging applications is not just legitimate, it's very much necessary. Otherwise all applications would just reserve as much RAM as they can convince the OS to give them, even if they have no real use for it. There is no checks for this in place, so users need to understand the technical implications and punish RAM hoggers by avoiding them.
If your application can utilize RAM to disproportionally speed itself up and therefore on average speed up the workflow of most users, then that's legitimate, too, and an informed user will see the value.
Yes, you can actually manage RAM more efficiently for your application, if you just reserve a whole bunch of it and work inside of that, but at best you'll trick your users into thinking your applications is fast, but it's not actually in the interest of the user. If they wanted to dedicate all RAM to your application, they would not have opened a second application.
This is the case. 8 GB of memory, VM takes half of it, Chrome will happily take the rest with few tabs open and lock up my computer.
I almost always find that this is caused by a badly behaved website, not Chrome itself.
Some sites have horribly written JavaScript, or introduce ads that run their own CPU- and memory-intensive JavaScript.
Finding and closing those tabs, or disabling JavaScript, or using uBlock or uMatrix usually solves it for me.
My computer at work has 16 GB. It gets slow. Every now and then, I'll open a web page that pushes things past a limit. The browser becomes completely unresponsive and sometimes I can't even move my mouse. While I'm suffering from running out of memory, the browser decides to use up even more memory to pop up a dialog to taunt me about it.
This can even happen without user action, for example when a page automatically loads a new ad. The ads on reddit seem particularly bad in this way. Randomly, one will eat all my RAM.
I often end up having to hold down the power button for 5 seconds. That, and pulling the power cord, are the only reasonable recovery. If I get "lucky", as I did a few days ago, Linux will kill the X11 server; this violently shuts down the whole GUI.
I really really hate the situation. I blame most of it on Chromium and Firefox, both of which don't make a serious attempt to keep things under control. A bit of blame goes to the fact that resources allocated in the X11 server can not be easily mapped back to web pages and thus kept within page-specific memory quotas.
If you enable the magic SysRq key, Alt+Print Screen+F will trigger the OOM killer.
Quick enable for those who want it:
in /etc/sysctl.d/90-sysrq.conf.> I blame most of it on Chromium and Firefox
I rarely have this problem with modern Firefox, but also block ads so maybe that makes the difference. Chrome is always bad, though.
The end result is roughly as bad as just rebooting, so I might as well just reboot.
There is no reasonable way to account for the memory.
The "reasonable way" to account for memory is to read the top(1) manual page to find out about the different memory usage statistics, then run top to find out which processes are using how much memory.
Your 66 MB is really low. Maybe your video driver is better than mine.
Fortunately I have a Linux desktop which is my primary machine, but I do still use this quite a lot when I’m working away from my desk.
Two reasons
1) Because, Chrome is ready to do something with that tab: browse the web. Do this, create a browser that doesn't use much memory when a tab is idle. Switch back to that tab and interact with the page or go to a new page. You will experience latency. It will feel slow. That's why the tab uses a lot of memory. It is staying ready at all times to be interacted with by the user and the network.
2) The real reason: Chrome either has no memory budget or the memory budget was set to 100 MB. The engineers decided that some amount of memory usage was acceptable and that's what you get. If a new budget was created, say 10 MB, then what you would see is some very clever engineering to overcome the problems in the first reason I gave. Chrome would be responsive at all times and use very little memory per tab, but at great engineering cost. It would be very difficult, but interesting work.
Google devs use 16-32 core machines, often with hundreds of gigabytes ram. Why would they bother optimizing?
https://randomascii.wordpress.com/2017/07/09/24-core-cpu-and...
Granted, I don't know anyone that uses that much and you would probably get asked by management for using a dev desktop that big but you can if you need to. I myself use just a i3.xlarge with 4 vCPU's, 30.5 or memory, Up to 10 Gigabit of EBS storage and 1 x 0.95 NVMe SSD.
My home machine has 4 i7 cores w/ HT, 32GB RAM & a 1TB SSD. Compiling stuff on that one is ok, although quite a bit slower.
* Literally every current MacBook except the 15" MBP
* iMacs unless you choose to upgrade the RAM
* My local PC retailers website has 34 models with 4GB of RAM, 84 with 8GB and 28 with 16GB. The cheapest 16gb laptop there is €1100. They also sell 3 Chromebooks and 1 windows 10 device with 2GB of RAM..
399 laptops with 4GB of RAM: https://www.pcgarage.ro/notebook-laptop/filtre/memorie-capac...
548 laptops with 8GB of RAM: https://www.pcgarage.ro/notebook-laptop/filtre/memorie-capac...
Less than 200 laptops, in total, with 16GB RAM or more. So probably less than 20% of the laptops on sale have that much memory, in 2018.
The "real" world is quite different to what us folks in IT see in our corner of the world.
these are gaming, most powerful PCs people are using. 8gb is 44% of all users.
No, workstations and\or graphical stations are powerfull. Gaming rigs can be powerfull, but most of the time they are average or just above average.
Also - steam statistic will show you a great number of PCs that are being used only to play some indie games and\or Dota. 8gb is more than enough for that.
My understanding is that they have rMBP laptops and slightly beefier desktops.
> The standard machine has 32 GB. So I guess 0.32 hundreds
His comment was in response to Opera 12.x takes ~3-10MB per TAB (+the weight of the media used on the page).
Many of the folks who work in our monorepo have an additional Linux workstation - not sure what the specs are on it, or what the average split is between laptop and workstation surfing. I also haven't paid that much attention to see if the folks I know on the Chrome team have substantially different usage.
Because they're also targeting Android devices.
You obviously have no idea what you are talking about. Most devs at Google use MacBook Pros.. which cannot even be upgraded to hold hundreds of gigs of ram.
The required build tools and software for the internal engineering systems aren't usually available on a Mac so you'll need to have a Linux machine (physical or virtual) somewhere to remote into to do any dev work (again some teams are different but the bulk of engineers use the centralised Google infrastructure for source control, builds etc)
In addition to the desktop, every engineer gets a choice of laptop (Mac/windows/Chromebook) as well for email, meetings and cat videos.
Non-engineering just get a single laptop. Many many people now pick to use Chromebooks.
Some people might say I shouldn't keep hundreds of tabs open for weeks. But I'm an old guy, and by my standards my laptop is a freakin supercomputer, so in my mind it should be able to handle all the web pages I can manually throw at it.
[0]: https://chrome.google.com/webstore/detail/the-great-suspende...
It’s not always happy if Chrome crashes or I have to do a cold reboot, but mostly it keeps Chrome’s gluttony under control.
But it's a much harder problem to solve than many think. For example, if they start "suspending" my slack tab, or my email tab, and I begin missing messages I'm going to be quite upset...
Instead what they choose to do is not worry about memory until it you actually run out of it. I don't mind my applications taking up 90% of my memory if that keeps everything fast and I don't have to worry about keeping track and thinking about what I actually want to suspend and what I dont't.
If you really do mind, just run any of the plugins that implements your exact required behaviour (like the great suspender).
> I'm going to be quite upset...
You'll get over it, I promise.
Why the extreme majority would want that from their browser all the time baffles me. Just to see a lower number in a resource monitor window?
I'm not. I open dozens of pages simultaneously routinely. 1 second here, one second there, it adds up.
Sure, it's not the end of the world, but those differences were why Chrome was better than Firefox.
How many times does that pretty-narrow situation happen to you in a day?
If you had such a memory-saving mechanism, boosted by prefetching the tabs adjacent to my current tab, it would barely cost me any seconds in an average week. Running low on memory is a big hassle taking a lot of seconds to deal with.
Great, then set vm.swappiness = 100
And stop complaining about about virtual memory usage.
You say you sometimes have "hundreds" of tabs open, I've done this too, but my laptop doesn't have 20GB of RAM, but it just seems to work anyway.
What I ended up doing was: just stop looking at resource monitors.
- Is 100 MB the marginal memory cost to add one more tab when you already have a bunch open, or is it the memory usage when you have a single tab open? Don't forget that there is a baseline amount of memory usage for the application itself.
- Measuring memory usage is hard, doubly so for web browsers. You'd think it would just be about counting all the allocations, but shared libraries, sandboxes, and cache make it complicated. Just looking at the "memory usage" panels in Windows/macOS is often misleading: unfortunately I can't find the link at the moment, but there's a great article about how for Chrome, the number you get in those panels is wrong.
- In response to the increasing demands of web standards, browsers have basically become mini-operating systems, and you'd expect them to have memory usage to match.
- Websites are complicated: DOMs get bigger all the time, and it takes memory to store them, especially with the aggressive optimizations browsers use (see next point)
- Browsers use a lot of techniques to maximize performance as much as possible: aggressive caching and JS engines that favor space-time tradeoffs for faster execution being the two big ones. But remember that these are all a question of degree: if there is less memory available, they will use less and just go slower. The browser is just using the RAM available.
tl;dr: you may not be measuring it correctly, it's a difficult problem space, browsers deliberately use as much memory as is available to optimize for speed
Allow me to partially disagree, it is true that browsers have basically become mini-operating systems, but not (IMHO) because of "increasing demands of web standards", because of "increasing demand of web publishers and all the crap that every other site has now embedded or is serving to you or is using to track this or that aspect of your visit".
A good question for the OP could be, how much memory does your Chrome use per tab if you disable javascript and open - say - 20 Hacker News pages?
> One tab on chrome takes about 100MB memory, why?
It probably doesn't.
Much of that apparent memory usage is shared between all tabs, and the browser renderer process, etc. in the form of shared memory.
Quite a bit of it will be the executable code itself, which is "mapped" into memory, given an address, and allocated the full size but doesn't actually consume memory until it needs to be read from disk.
And a large part of that memory is going to be the giant white pixel buffer that you want it to draw into, which is typically mapped to a texture buffer in the GPU memory.
Example: I've been doing some experiments around DWM thumbnails in MS Windows. My program doesn't really do much and shouldn't use too much memory (and doesn't, at least initially). I create a thumbnail for each visible window on the screen (say 5 of them), and -ding-, my process uses >400 MiB.
Or is the process totally different?
An HD pixel buffer is only 6MB.
Don't forget that the browser splits out different layers and composites them together, so it'll be a little bigger than that.
Current window size is 1280x800. Assuming the render buffer is ARGB32 and assuming one render buffer (which is probably an incorrect assumption) that should be ~40MB. The GPU memory is listed as a separate entry in that view, but I don't know if that is also included in the "private memory" listing.
Going turn off javascript and restart and see what it says then.
EDIT: 164 856 kB w/o JS. So no change (relatively).
Those RAM was really fully taken, unlike the VSZ. With more TABs my 8GB system will start slow down, as swap kicks in.
Yes I used the suspender but disabled it, sometimes it causes issues for me. I now depend on OneTab to use my computer properly.
Also, for special TABS it can eat so much memory that my system essentially stops responding suddenly, which is really annoying as you never know when it will happen. Can Chrome limit certain bad behavior TABs especially when it starts to take up all the memories?
I know each Tab is a process so it will not crash the whole browser, but the memory usage should be better handled no matter what.
E.g. I am developing a web photo editor https://www.Photopea.com . When you open large documents (dozens of layers in high resolution), it can use 4 GB of RAM or even more. That is simply because decompressed images are large. No matter what browser you use.
But I am still shocked about the memory requirements of some "modern" web apps. My app Photopea uses 80 MB after loading (with no documents open), because it has already loaded some brushes, patterns, gradients, shapes, and generated raster thumbnails for all of them.
GMail uses 280 MB right after loading. This is quite shocking, knowing that it should contain mostly text content.
What I'm missing here I'm honestly totally confused.
Gmail provides a lot more functionality with that JavaScript than you may think. There’s a fair bit of magic that goes into making an email client work as you want it to.
That being said: most web apps are surprisingly inefficient in their memory usage (I find it surprising, anyway), and Gmail is no exception. I last used Gmail a bit over a year ago on Firefox, and it tended to start at about 60MB of explicit allocations, and work its way up to about 110MB. (Chrome being generally less memory-efficient than Firefox at present, I understand that figure to generally be two or three times as much.)
But a good email client doesn’t need to be like that; compare FastMail (which company I work for, but this aspect of the design and awareness of memory consumption happened long before I joined): the current explicit allocations on my two FastMail sessions are: 10MB for my work account (mail, open for several days and used plenty), and 27MB for my personal account (mail has been open for a few days and used plenty, and then I just opened calendar, contacts, notes, files and settings, so that all the code for all of them is loaded and all their views initialised, and let it settle down from 53MB to 27MB).
A lot of these things come down to having people care about performance (time, memory or whatever axis you like). Having a large team often makes it harder to get right too.
Almost all news sites, even many blogs and should-be-very-bland web pages use more memory than FastMail.
It’s so fast and I really like what you guys are doing. Thanks!
Can you please convert your web interface into a generic mail user agent which works with all imap and smtp servers? This would be a much nicer solution than redirecting or fetching mails into a single account and imho your web interface feels snappier than MailMate on macOS and eMClient on Windows.
I just opened 'example.com' 6 times in new tabs, and mapped out the memory of the new processes. Total memory size: 10GB. Resident set size: 427.28 MB. Private dirty rss: 104.23 MB. I did the same thing with two new pages & processes just to make sure: 3.3450 GB, 144.532 GB, 36.876 MB.
example.com is a tiny html page. So, yeah, I don't know what the hell it's doing with all that memory. I don't think the devs care how much memory they're using.
>with say 30 tabs open, 3+ GB is gone, chrome is such a dominant memory consumer! in fact it takes about 10X more memory than everything else combined
The last words in OP's post were "is this a design fault?"
Yes.
(I now run Chrome in a Ubuntu VM under bhyve on FreeBSD, which has the same memory limiting effect, plus giving me U2F support when I pass a USB controller through to the VM)
Chrome tabs are processes with shared memory, but they're still processes. On Linux, they get kernel space mapped in. That influences their total footprint even though it's shared.
Can people just use what amounts of trifiling amounts of RAM in 2012 and stop demanding every executable be as "efficient" by an antiquated pre virtual memory metric, please?
Chrome is astonishingly good at what it does.
I understand the adage of free memory being wasted memory, but there's a context for that adage. E.g. if a user clicks off of a tab, the browser doesn't need to write that tab's contents to disk when 12 GB is free. A good trade off is to store the tab in memory, for X minutes. Write the tab (or more simply, the URL) to disk after those X minutes have elapsed.
Chrome allocates different process for every tab. Firefox doesn't do that. Just one process for all tab.
Suppose I open 10 tabs each on Chrome & Firefox. And suppose every tab needs 100MB of memory.
If you look up in task manager -
Chrome - 10 tabs - 10 different process - 100MB each = 1000MB = roughly 1GB
Firefox - 10 tabs - only 1 process - 1000MB = roughly 1GB for that one process.
Guess Firefox copied this feature from Chrome.
Closing and reopening is faster than doing the same in Chrome with far less tabs open.
IMO it's they usual software cycle of bloat -> optimization -> new features -> bloat -> optimization...
Features & non-features:
- it would generally work like the reader mode (no other modes) trying to place navigation links in a predictable place
- user can easily select text size and color schemes
- night mode (Android does not have one)
- because of it's content focus it could offer great offline capabilities like full-text search through archive and version comparison
- probably ignore most or all CSS
- probably no JavaScript support
- ad blocker for the rest
Can such a thing use it's own rendering engine on iOS? As I said I don't care about JS.
[0] https://en.wikipedia.org/wiki/Links_(web_browser)
[1] https://en.wikipedia.org/wiki/Lynx_(web_browser)
[2] https://en.wikipedia.org/wiki/Dillo
The night mode would be just a small additional setting on top of a color scheme selection.
Android did have a night mode, but it was experimental and removed in later versions. So other than alternative ROMs there's nothing there.
https://minbrowser.github.io/min/
https://www.reddit.com/r/dredmorbius/comments/6bgowu/what_if...
Also, ps_mem can be good for tracking what is using up your memory: https://github.com/pixelb/ps_mem
Oh, and of course everyone rolls their own, so that website with the dancing pigs not only has its own stack, but also one for every ad and tracking network it pulls in. It takes a whole lot of javascript to provide that transparent pixel!
The situation is no better on the server side, of course. Why write static HTML for your pageful of text when you can have a web framework pulling C++ from a SQL database, compiling it to web assembly on the fly and vomiting forth to the browser just in time because someone might want their flying unicorn background to have different colour sparkles and pointing those people at a different static location is just gauche.
No, I’m not bitter, far from it. It all makes work for the working man to do.
People want and expect websites to be very close to web applications that react to who you are, what actions you take on the page and a myriad of other factors.
That's just not possible with static HTML.
In all seriousness, we need waaay fewer layers of dynamic abstraction than actually get employed to solve most problems.
That reminds me of the thinking during the 90’s and early 00’s that everyone somehow must want 10 browser toolbars that spam them with ads all the time.
However, when you're on YouTube you don't want the site to suggest videos you're not interested in (or Amazon, products).
When you're on a blog, you don't want "related articles" to list articles you've already read.
Etc. Etc.
I don't know if people want this--in part because they don't even realize these features exist--but I'm sure the opposite can be annoying.
It also depends how modern techniques are used, but arguining that we have to go back to static HTML because it's better doesn't make sense to me.
On the performance side, Hacker News still takes 100MB of memory in Chrome, so...
(clientside that is; serverside it would be dynamic but Chrome should not be bothered, it is, but that is another story)
An example from the late 90s might be the idea that people wanted intro animations and music on web sites, heh.
Of course this wouldn't be a 'web browser' in the traditional sense, but a (reasonably) safe runtime platform for untrusted code without a central 'Big Brother' who decides what is good or bad for users.
I am perhaps too pessimistic here; wasm is young and has still to develop much of its own culture. I shall watch that space with interest.
(Seriously. Chromium is 124MB. How does anyone think web dev will go differently?)
Common sense is still required (which is unfortunately very rare in the modern programming world).
They've been doing a lot of work to cut it down lately. As wasm grows, and this becomes more of a focus, it should get really small.
On the other hand, LLVM's new backend means you can skip that runtime and get very tiny binaries; the smallest file I've gotten rustc to produce when compiling to wasm is just over 100 bytes.
Any example of where something like this is actually used?
I'm also interested in hearing why browser rendering code goes unused when displaying a javascript-powered site.