Last Comment Bug 844661 - Frame scripts use 170+ KB per tab (inProcessTabChildGlobal in about:memory), even for the not-yet-restored tabs
: Frame scripts use 170+ KB per tab (inProcessTabChildGlobal in about:memory), ...
Status: NEW
Product: Core
Classification: Components
Component: General (show other bugs)
: Trunk
: x86 Mac OS X
: -- normal with 21 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
Depends on:
Blocks: 447581 681201
  Show dependency treegraph
Reported: 2013-02-24 14:36 PST by Nickolay_Ponomarev
Modified: 2015-08-12 19:09 PDT (History)
30 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Description Nickolay_Ponomarev 2013-02-24 14:36:48 PST
Firefox loads a few content scripts for each tab:

The scripts are run even for the not-yet-restored tabs (created when restoring a session with "Don't load tabs until selected" preference checked), contributing (170+ KB per tab) to excessive memory usage being investigated in bug 681201.

in bug 681201 comment 73 Gavin says "I think it would be easy enough to eliminate that entirely now that we've dropped e10s support."

See for information about the message manager and content scripts.

0. Ensure the "Don't load tabs until selected" preference is selected
1. open 100 tabs by running this from the Error Console:
> for (var i = 0; i<100; i++) {"about:blank") }
2. Restart
3. Open about:memory, then click "Minimize memory usage" a few times

Here are the measurements (under explicit/js-non-window/compartments/non-window-global):
	17.49 MB (53.82%) -- inProcessTabChildGlobal?ownedBy=chrome://browser/content/browser.xul
	├──13.95 MB (42.93%) -- gc-heap
	│  ├───4.57 MB (14.05%) ── unused-gc-things
	│  ├───3.63 MB (11.16%) ── objects/function
	│  ├───3.52 MB (10.83%) -- shapes
	│  │   ├──2.42 MB (07.45%) ── tree/global-parented
	│  │   └──1.10 MB (03.39%) ── base
	│  └───2.24 MB (06.88%) ── sundries
	├───1.79 MB (05.52%) ── shapes-extra/compartment-tables
	├───0.97 MB (02.99%) ── objects-extra/slots
	└───0.78 MB (02.39%) ── other-sundries

Commenting out all the messageManager.loadFrameScript calls listed above makes the inProcessTabChildGlobal measurement disappear.

Uncommenting any one of them makes the inProcessTabChildGlobal measurement jump to 15+ MB.

The nsInProcessTabChildGlobal initialization (and presumably the JS execution) is called from nsXULElement::BindToTree for the <browser> element, see and nsXULElement::LoadSrc().
Comment 1 Marco Castelluccio [:marco] 2013-02-24 16:18:20 PST
This will probably improve startup times.
Comment 2 Caspy7 2013-02-24 16:54:26 PST
Forgive me if this is a dumb or non-contributive question, but does this affect us on non-desktop platforms as well? (aka, mobile)  I know that every bit counts on phones.
(If so, guessing the Platform fields can be updated.)

P.S. This is very exciting bug for those of us who keep many tabs open as this may make a noticeable difference in startup and memory usage.
Comment 3 Andrew McCreight [:mccr8] 2013-02-24 17:27:58 PST
B2G uses E10S so I don't think we can skip this there.  Android probably doesn't usually have so many unrestored tabs.
Comment 4 Nicholas Nethercote [:njn] 2013-02-24 19:20:44 PST
Yeah, I think the potential improvement in start-up times (something glandium complained about in the many-tabs case) is more interesting here than the memory reduction.
Comment 5 Olli Pettay [:smaug] 2013-02-25 00:37:01 PST
Note, we do cache the compiled frame scripts and just execute the compiled version each time
such is loaded.
Comment 6 :Felipe Gomes (needinfo me!) 2013-02-25 11:50:37 PST
> Uncommenting any one of them makes the inProcessTabChildGlobal measurement jump to 15+ MB.

Given this comment it seems that this memory isn't necessarily dependent on the the scripts' code but more likely to be a fixed cost from inProcessTabChildGlobal
Comment 7 Olli Pettay [:smaug] 2013-02-26 01:53:28 PST
Well, ofc we need to create the JS objects for each tabchildglobal separately.
It just shouldn't be the script itself taking memory, but the objects the script create.

Note You need to log in before you can comment on or make changes to this bug.