
Ask HN: One tab on Chrome takes about 100MB memory, why? - ausjke
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?<p>Yes I use onetab extensions etc to save memory, just wondering why one tab takes so much memory, is this a design fault?
======
keybuk
(I have worked as an engineer on both Ubuntu and Chrome)

> 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.

~~~
sebcat
If I Shift-Esc in Chrome with one tab open, it shows that this tab ("Add
Comment") consumes 0 bytes of shared memory and 163 828 kB of private memory.

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).

~~~
londons_explore
Zero bytes of shared memory? So you have no other processes running which have
libc loaded in?

~~~
sebcat

        $ ldd chrome | wc -l
             124
    

Shift-Esc is Chrome's own task manager. I don't know how they count.

------
tsukikage
Because it is 2018 and people have forgotten how to static HTML. All that
lovely rendering code in your browser goes unused as people rewrite it in
Javascript, badly; or even in C++ and then compile to web assembly, that’s all
the rage now, because why stick with one layer of abstraction when you can
involve three?

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.

~~~
flohofwoe
I don't know, WebAssembly compiles to very small blobs (if done right), you
can get a lot of functionality out of a few KBytes. Imagine if we could throw
out all the high-level crap from the browser core (WebAudio's node graph, all
the video and audio codecs, HTML/CSS/JS engines with all legacy features they
need to support, etc etc... and replace that with wasm modules which are only
loaded on demand. Then browsers would become much smaller, and web pages would
only need space for the features they actually use.

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.

~~~
tsukikage
I’ve not seen much WebAssembly “done right” to date; IME it is most often
employed to spew gargantuan legacy C++ applications verbatim into the browser
to avoid having to understand which parts are actually desired, whether and
how they can be unpicked from the rest, and whether they are trivial enough to
actually just reimplement in Javascript or otherwise as standalone modules.
This does not bode well for the utopia of small clean blobs you propose,
though I do agree it would be nice if it came to pass.

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.

~~~
Grollicus
Don't worry. If we've managed to blow our binaries up to 100s of MB, we can do
it with our websites, too!

(Seriously. Chromium is 124MB. How does anyone think web dev will go
differently?)

~~~
tluyben2
We will never go back ; there is only a tiny niche group (embedded, retro and
demoscene) that cares about tiny and efficient. The rest simply wants to
deliver features fast. On their (I include myself in that often) island, most
reason that computers are fast enough and have enough memory. But that
arguments really does not take into account things like: multitasking (if all
devs think like that, what happens when you run 20 apps at the same time?)
and, in many cases, battery life (that does not have to be the case; bloat
does not have to hog cpu but often does).

~~~
mwcampbell
It's better yet if we can deliver features fast with internationalization,
accessibility, security, maintainability, and so on. Whenever I dabble in
retro computing, usually via emulation, I appreciate how much progress we've
really made. And if a phone needs 2 GB of RAM, and a laptop needs 8, well, the
world has much bigger problems.

------
glibgil
> One tab on chrome takes about 100MB memory, why?

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.

~~~
DennisP
I'm perfectly willing to wait a second for the page to be reloaded from solid-
state storage, if I haven't visited the page for an hour or more.

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.

~~~
vageli
As a person who also has way too manu tabs open at all times, I've had success
with the great suspender [0]. It "suspends" pages after a timeout so they use
less memory.

[0]: [https://chrome.google.com/webstore/detail/the-great-
suspende...](https://chrome.google.com/webstore/detail/the-great-
suspender/klbibkeccnjlkjkiokjodocebajanakg?hl=en)

~~~
LordDragonfang
The current version also has a bug where it will create so many cookies on
google-owned domains that it will exceed the header limit and cause a 500
response. The dev refuses to fix it until he implements a feature to make
suspended tabs persist across updates, which is apparently slow going.

~~~
imhoguy
Well, it is opensource so anyone can fix it for fun or profit:
[https://github.com/deanoemcke/thegreatsuspender](https://github.com/deanoemcke/thegreatsuspender)

------
IvanK_net
In modern days, it is usually a web page / app, who takes memory, not the
browser environment itself.

E.g. I am developing a web photo editor
[https://www.Photopea.com](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.

~~~
maccam94
GMail has a ton of Javascript. The basic HTML interface uses closer to 10MB (a
bit tricky for me to measure in Firefox, since it doesn't use one process per
tab)

~~~
tmd83
And what functionality does it provide for that tons of javascript? I am
asking honestly because most of the magic of gmail (which I love) is on the
server side. The functionality that it has on the client side is trivial and
in some cases atrocious. In these days it cannot even resize the compose box.
The power of it's search bar should require trivial amount of client side
code, so should the auto save. The only thing that should take up memory is
client side caching of inbox which is primarily text.

What I'm missing here I'm honestly totally confused.

~~~
chrismorgan
(Key point: Gmail uses over 100MB where FastMail uses 10MB. Careful
engineering helps a lot.)

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.

~~~
tmd83
That's what I believe too. Thing's are always harder to implement than you
believe at first as a developer I know that. But even than the only
explanation I can think of gmail's heaviness is not caring. In some ways it's
even worse than a blog or news site which is often image heavy, required or
not than can at least use up a lot of memory. Gmail on the other hand is not
and it's something that is essentially meant to be opened for hours, gives a
simple interface that suggests it would be light whereas taking up more memory
than some bloated desktop client.

------
ausjke
I used the tool called ps_mem.py which measures both private memory and
resident memory, at the moment with 50 tabs it took 4.5GB.

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.

------
Waterluvian
I'm eager for info too. But while we're waiting, I have a genuine, not snarky,
question too: does this ever actually negatively impact people's use of their
computer? I can't recall ever feeling like my browser having lots of tabs open
has changed the experience. RAM and resource usage hasn't been on my mind in
years.

~~~
burfog
Yes indeed.

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.

~~~
minitech
> I often end up having to hold down the power button for 5 seconds.

If you enable the magic SysRq key, Alt+Print Screen+F will trigger the OOM
killer.

Quick enable for those who want it:

    
    
      kernel.sysrq = 1
    

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.

~~~
burfog
This would, in some way, let me regain control. Most likely it will have
killed the X11 server and dumped me to a text console login prompt. If not
that, maybe a browser will be killed.

The end result is roughly as bad as just rebooting, so I might as well just
reboot.

~~~
minitech
It typically kills the browser. Sure, it gets you the same result as rebooting
if you only have a browser open, but it’s much faster =)

------
peterwwillis
AFAIK, each tab in Chrome is a new process, rather than a thread. It's a lot
easier to waste memory on duplicate stuff. The operating system will try to
re-use as much memory as it can, but that's just a conservative guessing game.

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.

------
hawski
To my overly long TODO-list I added a web browser project. I would like to see
something akin to Links [0] or Lynx [1] with a bit of Dillo [2], but also for
mobile.

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)](https://en.wikipedia.org/wiki/Links_\(web_browser\))

[1]
[https://en.wikipedia.org/wiki/Lynx_(web_browser)](https://en.wikipedia.org/wiki/Lynx_\(web_browser\))

[2] [https://en.wikipedia.org/wiki/Dillo](https://en.wikipedia.org/wiki/Dillo)

~~~
codedokode
What's the use of night mode? Even if someone needs to browse web in the
darkness (which is a bad idea anyway), it should be implemented somewhere in
the OS, not in applications.

~~~
hawski
Sometimes you need to browse in the darkness. It should be implemented in the
OS, but it isn't. I don't have a mobile OS on my TODO list.

The night mode would be just a small additional setting on top of a color
scheme selection.

~~~
golergka
If it's not implemented in the OS, wouldn't it make more sense to create an
OS-level utility?

~~~
hawski
OS-level utility needs APIs that are not there in case of Android. All night-
mode apps for Android are just a reddish overlay. It often falls apart when
you something can't go through the overlay like AFAIR system passwords. I
tried to use apps, but met with this wall several times.

Android did have a night mode, but it was experimental and removed in later
versions. So other than alternative ROMs there's nothing there.

~~~
gusmd
My 1st gen Pixel XL has had night mode since I bought it 1.5 years ago, and it
has continued to work all the way to Android 8.1.0.

------
iKlsR
Try TidyTab,
[https://github.com/eggplanetio/tidytab](https://github.com/eggplanetio/tidytab).
Added benefits are it's a lot lighter and you get to sync your bookmarks
across your devices. I was a longtime OneTab user and I suggested several
features to the developer to make it just about the same feature wise for
anyone migrating.

------
elka
Memory usage of a browser mostly depends on the web page. Compare a static web
page with a JavaScript heavy web page that creates thousands of objects.

------
grapeli23
It's pure madness. Still in 2012/13, Google maps operated on a 32MB RAM system
(with desktop recording running in the background).
[https://drive.google.com/file/d/1xq4w2LD9ypv1zwv6oqPTciWvIDD...](https://drive.google.com/file/d/1xq4w2LD9ypv1zwv6oqPTciWvIDDPw9sd/view?usp=sharing)

------
Analemma_
There are several answers here:

\- 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

~~~
jaclaz
>\- 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.

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?

------
drewg123
When I ran an Ubuntu desktop, I ran Chrome in a container in order to limit
its memory use.

(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)

------
posterboy
It's rather obvious that chrome isn't intended for heavy duty as the tab bar
becoming unusable above ~20 tabs. So I use multiple windows instead and max
out 8 gb pretty quickly. I'm just glad it backs up dynamic content like edited
form fields before those tabs get crashed to free up space. Also, it's quick
to reach 7.9 gb, but goes a long way on that last ~100 mb. But of course a
long running js leaking memory on some news site can bring it down.

Two times in a month the login manager crashed and I couldn't get back in from
lock screen without killing a few processes manually on console. I'm going
back to Firefox with noscript and tree style tabs, as soon as I finished
working on all those open tabs ... so, probably never. I don't want to miss
the history search and security of chromium.

So I should learn to use the history sidebar instead of tree tabs, and use the
tab bar like a ring buffer, not a stack. And I should try deactivating js
globaly, if there is a whitelist built-in.

------
godelmachine
Well, here is one thing I observed.

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.

~~~
sebazzz
Sounds like your Firefox version is out of date. Multi process Firefox has
landed quite a while ago, with different memory and performance
characteristics.

~~~
godelmachine
I'll check.

Guess Firefox copied this feature from Chrome.

~~~
littlestymaar
Fortunately they didn't : they use one process for the browser UI, and a few
(like two or four) processes for tabs which are dispatched between those
process. It's way better than Chrome in term of memory consumption when you
have lots of tabs opened.

~~~
Sylos
I think, the number of processes (by default) is set to how many cores you
have on your CPU. That way you can achieve almost the maximum of parallelism
with a minimum of RAM use.

------
kbody
Try checking memory of a cryptocurrency exchange. A couple gigs after some
hours of activity. I would imagine that there's a memory leak, but it's weird
that this performance is consistent across all 3-4 exchanges I've been using.

------
olivermarks
I use Opera as my primary browser because Chrome is slow, a memory hog and
makes the fans on my macbook air really noisy

~~~
petee
At the core, Opera is still Chromium. Either way I use it primarily too,
certainly snappier than Chrome itself

~~~
olivermarks
I'm aware it is core Chromium but it seems to run way faster...

------
partycoder
Some lightweight browsers to try: dillo, midori, epiphany.

Also, ps_mem can be good for tracking what is using up your memory:
[https://github.com/pixelb/ps_mem](https://github.com/pixelb/ps_mem)

------
ianai
In large part, I suspect, chromes resource use stems from google wanting to
scour everything you do. I wouldn’t be surprised to find out it logs how many
seconds your cursor is over ads and all other user input.

------
logicallee
Yes, it is a design fault.

~~~
wejick
What is design fault? Could you elaborate

~~~
logicallee
The OP described the current design:

>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.

------
zspitzer
I can't find the link, but there was something recently about how size of the
js runtime has increased over time as all the new (es6) features have been
added

------
superkuh
Well, it's not a priority for them. Pick a browser that prioritizes
performance for web browsing instead of running JS web apps.

------
askvictor
Not a direct answer to your question, but 'the great suspender' extension puts
unused tabs to sleep.

------
qweqweqweqw
Yesterday I had to restart chromium on my computer, because it ate all 32GiB
of RAM.

------
petee
Only 100? Consider yourself lucky!

~~~
mrep
I know, I'm sitting at 2.2GB on mac with 4 open tabs.

------
gcb0
well, using the current fad terminology: it is because every tab is a Native
App. (i.e. an electron app -- i.e. a web page)

------
KirinDave
Hey. Hey.

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.

~~~
noxToken
I don't need every application to be the leanest that it can be. What I need
is for every application stop assuming that 12 GB of free memory means that
it's their 12 GB.

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.

~~~
littlestymaar
Free memory isn't wasted memory though, it's file system cache memory ! If a
software uses 100% of the available RAM, it means all your file system call
are going to be hard drive IOs (not everybody has ssd mate).

~~~
KirinDave
If you actually cared about this you provision a ramdisk. But this is a
talking point, not an actual argument.

