What's specifically happening when a browser starts slowing under tab load?

Started by Coldblackice, June 11, 2014, 06:50:51 PM

Previous topic - Next topic

Coldblackice

Browsers start to get sluggish and unresponsive under increasing tab load. What/Where specifically is the source of this slowness, and could it possibly be "boosted" in some way (other than limiting tabs)?

Obviously, there's a heavy load on memory when you have 100+ tabs open. But if there's a copious amount of RAM + page file available, why does it still get slow? What function or mechanism is the source of the slowdown? Is it on the browser's side of responsibility, or the OS'?

Without the Firefox source code, I'm wondering if there's some measure I could tweak to circumvent the slowdown, like perhaps manually allocating metric-ton of disk cache, or something.

(For reference, speaking of 64-bit browsers)

edkiefer

It depends on what sites you have loaded , social sites or sites with a lot of scripts running will slowdown browser, especially with many tabs . not sure much you can do if these slowdowns don't hit a CPU% limit to have PL do something.
Bitsum QA Engineer

BenYeeHua

Firefox?
It is because main thread is getting blocked by rendering or JS engine of the content/page you are browsing, and you can only wait until e10s and other thing like OMTC(which is landed on Nightly, and waiting more feature like APZ) coming to released version.

Until e10s+OMTC+other OMTx is coming, there is nothing much we can do. :P
(of cause you can change your browser to IE11 or Google Chrome to get the similar snappy feature too)


https://wiki.mozilla.org/Electrolysis
https://wiki.mozilla.org/Platform/GFX/OffMainThreadCompositing
http://benoitgirard.wordpress.com/2012/05/15/off-main-thread-compositing-omtc-and-why-it-matters/
https://wiki.mozilla.org/Platform/GFX/APZ

Coldblackice

Quote from: BenYeeHua on June 12, 2014, 06:45:16 AM
Firefox?
It is because main thread is getting blocked by rendering or JS engine of the content/page you are browsing, and you can only wait until e10s and other thing like OMTC(which is landed on Nightly, and waiting more feature like APZ) coming to released version.

Until e10s+OMTC+other OMTx is coming, there is nothing much we can do. :P
(of cause you can change your browser to IE11 or Google Chrome to get the similar snappy feature too)


https://wiki.mozilla.org/Electrolysis
https://wiki.mozilla.org/Platform/GFX/OffMainThreadCompositing
http://benoitgirard.wordpress.com/2012/05/15/off-main-thread-compositing-omtc-and-why-it-matters/
https://wiki.mozilla.org/Platform/GFX/APZ

Ah, very interesting. Thanks much for the info. Too bad this functionality hasn't been available earlier (and even now)!

Could there be anything done now to workaround the issue? For example, there's a Firefox addon called "BarTab" that unloads idle tabs after a certain period of activity. When you eventually jump back to an unloaded tab, it's an empty/blank page, but then automatically starts loading the page it was on before unloading.

In my experience, however, it seemed unclear if it was actually having a benefit of lightening the resource load. Would this theoretically work to get around the issue? I may take this on as a personal project, if so.

edkiefer

I would first see if less tabs helps , or see if any one tab is causing a lag .
I found that BF4 web site (battlelog) was causing issues .
1) it has a background image script running that eats CPU% ,especially if you have hardware acceleration off in browser (FF) .
Second I was getting delays in mouse wheel and other input (delayed menus etc) with this tab (BF4 open) even though i was not on that tab .

So see if you can track it down and try not having that tab always running .
Bitsum QA Engineer

BenYeeHua

Quote from: Coldblackice on June 15, 2014, 08:06:23 AM
Ah, very interesting. Thanks much for the info. Too bad this functionality hasn't been available earlier (and even now)!

Could there be anything done now to workaround the issue? For example, there's a Firefox addon called "BarTab" that unloads idle tabs after a certain period of activity. When you eventually jump back to an unloaded tab, it's an empty/blank page, but then automatically starts loading the page it was on before unloading.

In my experience, however, it seemed unclear if it was actually having a benefit of lightening the resource load. Would this theoretically work to get around the issue? I may take this on as a personal project, if so.
Unload the idle tabs did helps the CPU Usage, but it don't helps Memory Usage as Firefox will cache the data for reopen it back faster.
So if your slow down is caused by the GC(which is depend on Memory Usage, more Memory Usage=slower), I think you can only get a fast CPU and RAM to speed up the GC process, or just restart Firefox to unload the tabs, with "Don’t load tabs until selected" ticked, and using Restartless to restart. :)
https://addons.mozilla.org/en-US/firefox/addon/restartless-restart/

Coldblackice

Quote from: BenYeeHua on June 15, 2014, 11:02:15 AM
Unload the idle tabs did helps the CPU Usage, but it don't helps Memory Usage as Firefox will cache the data for reopen it back faster.
So if your slow down is caused by the GC(which is depend on Memory Usage, more Memory Usage=slower), I think you can only get a fast CPU and RAM to speed up the GC process, or just restart Firefox to unload the tabs, with "Don’t load tabs until selected" ticked, and using Restartless to restart. :)
https://addons.mozilla.org/en-US/firefox/addon/restartless-restart/

So just to clarify -- unloading tabs won't be the same effect as restarting Firefox (with "don't load tabs")?

Would it be possible to unload idle tabs while also removing it from cache (but without having to restart Firefox)?

BenYeeHua

This can be a long post....

So far, unload the tabs will never having the same effect as restart, just like Windows.
But it may improved after “Compacting Generational GC”  is supported, and it(the bug) has been silent, as there are too much for Mozilla to care about.
https://blog.mozilla.org/nnethercote/2014/03/31/generational-gc-has-landed/
https://bugzilla.mozilla.org/show_bug.cgi?id=650161

For unload idle tabs while also removing it from cache, someone said that you can do this by setting browser.sessionhistory.max_entries to 0, or at least 1-5 for reducing the cache without completely turn off it.
----
With Nightly, you can try using e10s, but remind that it is still buggy.

As default, it should be all tabs in 1 process, but you can change it to each tab per process by changing the dom.ipc.processCount to max.
But remember that this will making it more buggy than the default design, so I will not suggest to playing with it.
https://wiki.mozilla.org/Electrolysis

And for reducing the memory usage, you can also try not using adblock plus, but using the other adblock that using Proxy/software(Ad Muncher, for example), not addons.
https://blog.mozilla.org/nnethercote/2014/05/14/adblock-pluss-effect-on-firefoxs-memory-usage/

Coldblackice

Gotcha, thanks for the info.

What about this addon -- is it possible it could successfully mimic a browser restart?

https://addons.mozilla.org/en-US/firefox/addon/freememory/

BenYeeHua

Nope, this is just only works for Ghost Windows that need to GC a few times to remove it. ;)
http://jlebar.com/2012/5/30/A_ghost_story.html
But yes, normally Ghost Windows are not removable via GC, you need to file a bug to Bugzilla, then find out how it happen, and fix it.

So, it is just a addons that provide a shortcut to access about:memory to use Firefox own ways to force GC and CC, Firefox will run GC and CC per few second, if you are opening and closing page, or run JS/HTML5. :)
---
Anyways, if you want Firefox can nearly return to the level of memory usage after a browser restart, I think the only ways is speed up the process of coding compacting GC and the other thing that it need to start working.
The issues is GC fragmentation or heap fragmentation, so I think compacting GC will helps here, but we don't know the result if it is not tested yet. ;)

And here is some info about it.
http://stackoverflow.com/questions/2663292/how-does-heap-compaction-work-quickly

You can just read from this line, the image and words has a good information about why after GC, the memory will not drop back to the level that just start up Firefox.
QuoteFragmentation of the heap is a common problem faced by C and C++ applications and it happens under certain allocation patterns that sometimes are outside the developer control. For example, consider the following allocation pattern:
http://www.mono-project.com/Generational_GC

And here is the info about memory usage and performance.
https://blog.mozilla.org/nnethercote/2012/02/08/the-benefits-of-reducing-memory-consumption-2/

Coldblackice

Thanks a lot! Very helpful information, and I appreciate your sharing it. Good to know -- I guess I'll stick with browser restarts for now, then :)

BenYeeHua

You are welcome. :)

And to minimize the bad effect of higher memory usage which is increased GC time, you can overclock your CPU and RAM.

I has compared a bit with the other guy, my little Laptop i5-3210m used 100-180ms for GC, but with the nearly same amount of memory usage, his Desktop i7-3960x just used 10-30ms for GC, which only lost 2 Frame(60FPS, 1 frame is 16.67ms) for GC.

And if only iGC happen most of the time, then he is nearly will not notice the stutter.
(iGC, by making GC to part, and running it difference time, the GC total time increased, but each time the browser freeze will be reduced)
---
And ya, Ad muncher 5 will be free, so it is a good choose to replace Adblock Plus which increase the memory usage.
But I don't tried yet(as they are preparing the server side to accept more people connecting, or human DDoS ;D), so I am not sure how it is. :)

http://www.murrayhurps.com/blog/ad-muncher-announcement
http://www.murrayhurps.com/blog/ad-muncher-history

Coldblackice

Quote from: BenYeeHua on June 26, 2014, 07:31:04 PM
You are welcome. :)

And to minimize the bad effect of higher memory usage which is increased GC time, you can overclock your CPU and RAM.

I has compared a bit with the other guy, my little Laptop i5-3210m used 100-180ms for GC, but with the nearly same amount of memory usage, his Desktop i7-3960x just used 10-30ms for GC, which only lost 2 Frame(60FPS, 1 frame is 16.67ms) for GC.

And if only iGC happen most of the time, then he is nearly will not notice the stutter.
(iGC, by making GC to part, and running it difference time, the GC total time increased, but each time the browser freeze will be reduced)
---
And ya, Ad muncher 5 will be free, so it is a good choose to replace Adblock Plus which increase the memory usage.
But I don't tried yet(as they are preparing the server side to accept more people connecting, or human DDoS ;D), so I am not sure how it is. :)

http://www.murrayhurps.com/blog/ad-muncher-announcement
http://www.murrayhurps.com/blog/ad-muncher-history

Cool! I'm excited to try it out.

As for the GC -- how did you do those tests + comparison? Were there tools you two used?

I'd like to do that test on my own machine!

BenYeeHua

Quote from: Coldblackice on June 27, 2014, 08:17:07 PM
Cool! I'm excited to try it out.

As for the GC -- how did you do those tests + comparison? Were there tools you two used?

I'd like to do that test on my own machine!
You just need the same Firefox profile(which include all your history, addons etc), and also same Windows, then install Memchaser.
https://addons.mozilla.org/en-US/firefox/addon/memchaser/

For testing, I think opening some website that having heavy JS(Gmail is a good choose, YouTube too), or just opening many same website/tabs that will increase the memory, when it increased to similar amount of Memory(at least 500MB), click on Memchaser(you may need to click the hamburger menu-customize, and put it on the addon bar etc.), click "Reduce Memory".
It will showing GC:XX.X ms, which is mostly happen when you are closing heavy JS tabs.

Then just browsing normally(like me typing now ;)),after a few seconds, it should be showing iGC:XX.X ms, and this is mostly you wanna care about. :)

If you are interesting about lower Memory usage will getting what result, just open the Firefox, then click on "Reduce Memory", and see how much the GC time is.
----
And ya, by switching to Windows 8+(If you are using Intel CPU), you should seeing some performance increase too. :)

Coldblackice

Quote from: BenYeeHua on June 28, 2014, 02:21:17 AM
You just need the same Firefox profile(which include all your history, addons etc), and also same Windows, then install Memchaser.
https://addons.mozilla.org/en-US/firefox/addon/memchaser/

For testing, I think opening some website that having heavy JS(Gmail is a good choose, YouTube too), or just opening many same website/tabs that will increase the memory, when it increased to similar amount of Memory(at least 500MB), click on Memchaser(you may need to click the hamburger menu-customize, and put it on the addon bar etc.), click "Reduce Memory".
It will showing GC:XX.X ms, which is mostly happen when you are closing heavy JS tabs.

Then just browsing normally(like me typing now ;)),after a few seconds, it should be showing iGC:XX.X ms, and this is mostly you wanna care about. :)

If you are interesting about lower Memory usage will getting what result, just open the Firefox, then click on "Reduce Memory", and see how much the GC time is.
----
And ya, by switching to Windows 8+(If you are using Intel CPU), you should seeing some performance increase too. :)

Thanks. With memchaser, what are good numbers to have? Currently, I have -- Resident:2900MB, iGC:214.2ms (11.6s), CC:108ms (11.6ms)

I realize those probably aren't very good, but what could I do with that information? Or what could anyone do with that information? How could it be used to help better anything?

Also, is it possible to see if any of my addons are abusing memory? I've heard Adblock Plus abuses memory, but I'm not sure whether mine is or not.

BenYeeHua

Yup, very bad...

It should be caused by huge memory usage, as GC is affected by how many thing it need to looking for.
You should go to about:memory and check for it, it should showing something about the memory usage.

You can just save/export the about:memory by using the button on top, but keep in mind that it contain sensitiveness data like the website that you are browsing.

For the good number, I would said that <100ms is acceptable, <50ms is good.

Coldblackice

Thanks. Is there anything I can do to improve it? Or how can I find the specific culprit that's causing the problem?

Jeremy Collake

It depends on a great many factors.

The bottleneck could be any one or combination of the usual: virtual memory/RAM, CPU, I/O, etc..

You would have to profile the system and do some advanced analysis to determine what the bottleneck is exactly.

If the bottleneck is the CPU, it should be reasonably obvious.

So, the first (well, second) thing I would check is to see if Firefox has an excessive number of page faults occurring. This would indicate a lot of paging activity.
Software Engineer. Bitsum LLC.

BenYeeHua

Ya, and reducing the Firefox memory usage is a good choose to improve the performance, or reduce the GC time, which cause stutter.

For finding the cause, you may browsing the about:memory, it should showing who is/are using many memory, which I said many times before. :)
If it is showing the heap overhead, then finding who or which website js is biting many memory, then reduced after you closed it.
Or if it is showing ghost-windows, then there are some add-ons is leaking the memory.

Anyways, there is not a lot we can do except waiting for Firefox improve their GC, or async scrolling, e10s etc.
Or cause, regularly restart the Firefox is always a good choose, and finding who is using a lot of memory, trying to avoid it or use a better similar one.
----
Talking about profile, that is a good choose, but I don't think most people know how to read about it... :P

Autumner

Quote from: Coldblackice on July 27, 2014, 07:01:59 PM
Thanks. Is there anything I can do to improve it? Or how can I find the specific culprit that's causing the problem?
I had similar problems with Firefox. I suggest you give Pale Moon a try. It keeps the old UI and several other features now gone from Firefox. Relative to this thread, it's more stable and responsive even with loads of tabs open - although that's to be avoided, the Flash plugin is often to blame for slow-downs, too.

edkiefer

Yes, I use Palemoon too, i normally have 25+ tabs open and never have issue in general except what I mention above with battlefield (BF4) site, which you can fix .
Bitsum QA Engineer

Coldblackice

Quote from: bitstuart on March 04, 2015, 10:53:44 AM
some very insightful information here. Thanks, definitely learned something this afternoon!

Agreed! I was just on my way back here to ask Ben and others if there have since been any developments in this realm of tabs/memory/cache load with Firefox. It's still a daily frustration that Firefox begins to break down under tab load, necessitating a restart. I would *love* a way to clear out the cache "live".

I've been contemplating coming up with a solution to this for some time now. The basic principle I think would be key is the ability to unload unused tabs, reloading them upon revisiting the tab. I don't understand why this wouldn't be feasible.

In this same vein, an alternative is, when ctrl-clicking tabs you want to read later, instead of opening the tab and browsing to the page, it instead adds the new-tab to a "queue" that can be opened any time later -- either merely adding the tab to some list of links like read-it-later, or opening a new tab but preventing it from actually loading the page right away.

Thoughts/ideas anyone?

Jeremy Collake

I would have to investigate the issue. I'm sure the Firefox developers are aware, but they are also no doubt underpaid and overworked, and largely volunteer.

It would be interesting to discover the cause of it's poor performance during high tab loads, especially as compared to other browsers.

I would prefer to know the cause prior to speculating on a kludge to get around it. But, that's not always possible.

If you guys get a clue on this, I'll toss in my two cents, and maybe functionality.

I'd recommend letting me know which resource seems most saturated during these times. Use the Resource Monitor if you do, it's easiest.
Software Engineer. Bitsum LLC.

Jeremy Collake

... And an interesting side-note, for those not aware, is that Google Chrome, being one of the few Windows applications that forks itself (spawns new instances of itself that share memory), uses a ProBalance-like mechanism to keep it's background tabs 'in check'. I'm sure Firefox does something similar on a thread priority level.
Software Engineer. Bitsum LLC.

BenYeeHua

Quote from: Coldblackice on March 12, 2015, 02:15:54 PM
Agreed! I was just on my way back here to ask Ben and others if there have since been any developments in this realm of tabs/memory/cache load with Firefox. It's still a daily frustration that Firefox begins to break down under tab load, necessitating a restart. I would *love* a way to clear out the cache "live".

I've been contemplating coming up with a solution to this for some time now. The basic principle I think would be key is the ability to unload unused tabs, reloading them upon revisiting the tab. I don't understand why this wouldn't be feasible.

In this same vein, an alternative is, when ctrl-clicking tabs you want to read later, instead of opening the tab and browsing to the page, it instead adds the new-tab to a "queue" that can be opened any time later -- either merely adding the tab to some list of links like read-it-later, or opening a new tab but preventing it from actually loading the page right away.

Thoughts/ideas anyone?
Er...
Bookmarks that added into a "Read Later" folder, and delete it after you has open it? ;D
----
Anyways, not too much improvement to the Memory, just the time for full GC increased to 200+ ms(no idea why...), but most of the time it will just minor GGC.(if my memory does not fail me)

Quote from: Jeremy Collake on March 12, 2015, 02:26:46 PM
... And an interesting side-note, for those not aware, is that Google Chrome, being one of the few Windows applications that forks itself (spawns new instances of itself that share memory), uses a ProBalance-like mechanism to keep it's background tabs 'in check'. I'm sure Firefox does something similar on a thread priority level.
No idea, as I don't has the ability to read the code yet. :P

But for Chrome, I know it like to TRIM all the tabs into Page File when you just switch into background.
So each time you are browsing a webpage with many image, switch it back, then you will hang for a few seconds or 30 seconds for facing a frozen webpage, then switch to another tab and facing another white page...
If you switch back to other processes again, then it will repeat...

This is very... I was only open 5 tabs and it want to TRIM the tabs.... :P

Jeremy Collake

Interesting, and thanks for starting this thread.

I think FireFox-centric SmartTrim handling may be possible. I'll do some experimentation and get user feedback.
Software Engineer. Bitsum LLC.

BenYeeHua

Just saying, there are more than 2 peoples that want to use TRIM to trim Firefox, and one of them just give up and just become changing the Firefox code directly. ;)

Coldblackice

Quote from: Jeremy Collake on March 12, 2015, 04:43:47 PM
Interesting, and thanks for starting this thread.

I think FireFox-centric SmartTrim handling may be possible. I'll do some experimentation and get user feedback.

Any update on this experimentation? :)

I'd love to help out with the feedback part, if possible!

Jeremy Collake

Not yet. It's been more than a rough month, I've barely kept up with Lasso :o.
Software Engineer. Bitsum LLC.