You need to be logged in to post in the forums. If you do not have an account, please sign up first.
Stop execution of javascript and plugins in background tabs
Hi,It would be very nice to have the option to *stop the execution of javascript and plugins (Java, Flash, etc...) in background tabs*.
Some heavy sites and bad programmed sites are very aggressive with cpu usage.
For example big newspapers have lots of Flash and scripts running in the background. When I have several pages of a newspaper open, Opera hogs my cpu.
Most of the time it is not necessary to have all this code running in background tabs, using cpu cycles, making the PC less responsive, wasting watts and polluting with dirty energy (coal and nuclear in my country).
This would improve the speed and user experience of Opera *a lot*.
Hope to see it implemented soon! :-)
Also, I would like to say thank you to the artist-programmers at Opera for this great browser (v12).
It makes my PC feel faster with every release! :-D
And happy browsing to all in the Opera community! :-)
Hoch.
The W3C is working on the Page Visibility API for exactly that purpose.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]
It won't break the pages, it would pause them.
This is what Android devices do, for example, to avoid hogs on phones or tablets.
As I said in my first post it should be an option that you could enable for all tabs or selected tabs.
Another possibility is to give a lower cpu priority to threads of background tabs.
It is absurd to have tens of tabs (I usually have 20-30 open), executing, most of the time, *useless* background tasks.
Greetings! :-)
Hoch
Originally posted by hochmartinez:
It won't break the pages, it would pause them.
I think he meant that implementing your wish to where it had 0 potential to break pages, might be super hard to the point that it's likely that any implementation attempt at your wish would have a big chance of breaking pages.
I'm a little pessimistic too.
But, if done perfectly, your wish would be pretty cool.
Originally posted by serious:
The W3C is working on the Page Visibility API for exactly that purpose.
Yeh, I think this is the way to go.
You can't break a process (program) or thread if you just pause it.
You will suspend execution, that's all. Suspend does not mean stop execution.
This is what android does. Try to play a flash movie in the background of a Android phone or tablet, for example.
To avoid cpu hogs, like the ones every Windows user experience all the time, Android pauses execution of processes.
The title of this thread should be: "*Suspend/Pause* execution of javascript and plugins in background tabs"
Good browsing! :-)
Originally posted by hochmartinez:
You never heard of things like race conditions, keep alive, or timeouts, did you?You can't break a process (program) or thread if you just pause it.
PS: The only thing that you can do without potentially breaking existing code is stopping/postponing screen updates (eg. when playing a video ... and also only as long as some script does not read the current screen state, eg. to make a "screenshot"[1]), but that has nothing to do with script execution. The hard part is always that your changes have to stay transparent to the client (in this case: the scripted website).
[1] technically, not really a screenshot, but a website snapshot.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]
8. June 2012, 14:18:33 (edited)
Why do you assume I never heard about race conditions, keepalives and timeouts?
Do you know me? Do you know what I do?...
Have you ever build a multithreaded server, with high concurrency and availability, that real users use?
I've built several of them.
I happen to build pretty complex multithreaded programs, like http servers or app servers with compiled languages like Delphi or C++. I also have large experience in front end programming (Javascript, CSS, DOM, jQuery), in real life projects.
Back to your question, you are mixing concepts. You are talking about different things:
1. Race conditions happen when several threads in a process, like Opera, (or several processes) update the same resource at the same time. So, If we pause threads, less race conditions are likely. Anyway, good multithreaded programming use locking, so you won't have race conditions. I can't see your point.
2. Keepalive and timeouts are used *during* the connection between a client and a server, in that case (Opera) and the HTTP Server. When all data from the request (HTML, css, js, flash, images...) is received by Opera, the connection between the HTTP server and Opera ends. Once the page is loaded in your tab, usually, there is no connection to the http server, so no keepalives and timeouts are needed. So if you pause the tab, once data is loaded, you won't have any issues. Unless You have background Ajax scripts. If this is the scenario you were thinking about, the Ajax javascript code could break if the tab is paused, if it is badly programmed. You have to be able to recover from a broken Ajax HTTP connection, try again or throw an error. You have to program with failure in mind.
So, again, If you pause javascript, java or flash in a Opera tab, you won't break any (well programmed) code. You'll just pause the execution and:
- Save precious CPU cycles,
- Have a cooler computer,
- Hear less fan noise,
- Waste less energy (and pollute less),
- Have a more responsive computer.
Anyway, maybe someone from Opera could chime in. We are talking about the internals of a program we did not build.
Happy browsing!
Originally posted by hochmartinez:
While what you say is true in the http-context you have to think in the application context. Eg. I know a bunch of Rest APIs which automatically invalidate your login tokens after x minutes of not making any requests. So, if you stop JS execution there is no timed keepalive/session refresh and the user is logged out.2. Keepalive and timeouts are used *during* the connection between a client and a server, in that case (Opera) and the HTTP Server.
Regarding race conditions: consider having multiple open tabs with the same (editable) content. if you stop execution in one tab at an arbitrary time while changing content in another, and then (naively, as your app doesn't know it gets stopped) resume execution in the first tab, you can quite easily do stupid stuff (eg. by pausing just before tab 1 uploads, then changing content in tab 2 and save, then resume tab 1). While this may not be a common case, it is quite surely a factor which has to be taken into account.
Thus: Page Visibility API is the solution, as it is designed to enable apps to cope with all that stuff in a sane manner.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]
SOCKS ALREADY! + Gopher ∥ sys notifications ∥ +Info Panel ∥ dæmon mode ∥ etc
Mi web
GULIX -- Araucanía
Opera can adapt to the world, but that should not be at the cost of making any of them both stupider
Originally posted by RyanChappelle:
what would be the difference?for the feature to pause (not stop)
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]
SOCKS ALREADY! + Gopher ∥ sys notifications ∥ +Info Panel ∥ dæmon mode ∥ etc
Mi web
GULIX -- Araucanía
Opera can adapt to the world, but that should not be at the cost of making any of them both stupider
You are talking about very, very specific situations here...
I'm a heavy user of Opera since v5 (20 to 30 tabs open most of the time).
I'm a web backend/frontend developer, a nerd and a geek, and I can tell you, I can't remember the last time I needed code executing in background tabs.
Most of the web pages that I know, execute code (Flash, Javascript, Java) to refresh content for a human viewer. It doesn't make sense to have all this code executing all the time, while you are not watching at it, because it is hidden in a background tab.
Open 20-30 tabs with Opera, open a tab with 'Opera:cpu' and watch them overloading your computer while you are browsing/watching *a single tab*.
I'm tired of hearing my laptop fan kicking because those bits of code, than I'm not watching, are frying the CPU.
I'm tired of seeing my computer being slowed down by this CPU "vampires".
And what about end users? They don't care a bit about code executing in the background, but I can tell you, they care *a lot* about responsiveness.
I'm not proposing something new, this is what platforms like iOs or Android do by default. And Opera is a platform. Why? Responsiveness! It is absurd to have you phone, tablet or computer hogged by a, usually badly written app or in that case, a web page, that is not in the foreground.
With this option, Opera would have far better responsiveness.
In a previous post, I was proposing an option enabled by default to *pause* code execution, that you could disable for specific tabs.
And as RyanChappelle proposes, it would be nice to be able to enable it for specific domains.
Add to this on demand loading of tabs (enabled by default in Firefox 13) and you will have a *far better* browsing experience.
I will repeat again the immediate benefits:
- Save precious CPU cycles,
- Behave better with other apps/processes,
- Have a cooler computer,
- Hear less fan noise,
- Waste less energy (and pollute less),
- Have a more responsive computer.
Happy browsing!


[ Tweedo Monitor - Deluxe Website & Service Monitoring ]
I'll give a few examples :
- i listen youtube instructional videos (i don't actually watch the video, i just listen to it while i do other stuff)
- i let my webmail (gmail) open and check the tab only if the number in the tab's title changed
- i let facebook open and check back only if i get the notification that i received a message
all of the above would fail if the background tabs would have their scripts/plugins paused or stopped.
So, unless is a "per tab"/"per website" setting, it won't be helpful for me.
I would be ok with even dropping all data and reload the page if it was _MY_ choice.
Whatever shit needs to stay in RAM or could be dumped to disk or reloaded is up to someone else to decide. Personally I'd want it make it go out of RAM to.
But then on the other side that may be the virtual memory managers task and if it unused in a way which let that put it on disk then that's likely better.
Suspend them, after a user have not visited the tab for 30 seconds.
OF COURSE, there must be an option to turn this of/off,
and of course there must be site preference for this - because, say, google docs, or youtube/soundcloud should NOT be suspended, while i'm reading other tabs

But good idea. All notebook users will appreciate that.
@serious
sites break ? to hell with them. When news sites need more cpu that games, let them "break". I only need to read them anyway.
And site specific preference remove this concern.
p.s.: try going above memory threshold on iOS or win8, and see how gracefully your experience degrade
Tip: your app or tab will just get closed. And you can't live with it and kill Opera to restart it.
Just to find that it use the same amount of resources afterwards because it loads up all the same shit once again.
In Firefox it doesn't because it remember what you had visited first but it doesn't bother loading and showing it until you actually click those tabs.
Of course it would be even better if I could just leave firefox and have it as clean as a newly re-started one but the issue with that would be if say text areas was cleaned out after you had switched tabs. So I guess kill to clean is one option.
Alternatively you could mark tabs as in "keep data in this tab" / "don't dump the content of this tab when I switch to another one."
Guess the solution is to paste all urls to a text file and manage tabs that way, hurray!
Originally posted by iWasHere:
Just stopping the execution doesn't have to break the tabs once you go back either I suppose. Eventually depending on what they was doing. Maybe one could have some kind of realtime tag or whatever for scripts which shouldn't be stopped from execution.+1 many website these days abusing JavaScript for nonsense features that suck up all resource, we don't need all of 'em running in the background all the time.
I would be ok with holding the data if it could be swapped of rather than held in RAM.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]
Just because pages will, at some point in the future, have the capability to detect- doesn't mean that wouldn't be a great feature for the browser. The pages that would "break" from being paused are only the ones that would "break" from me leaving a Wifi network for a while, or hibernating my computer.
Both of which people regularly do.
People could set it in preferences, just as they do with playing/not playing plugins; a "pause execution" style button, or setting a domain to "pause after X seconds of not being viewed" - alternatively, setting all pages to pause after X seconds, and then setting them to stay "on" selectively.
There's already the feature to disable plugins; I just don't seen a good reason not to have it.
Sure some television play page may accept stopping (or maybe not because it want to keep on playing in case the user want to), but would say facebook do or may it want to run to keep chat going or whatever?
Maybe it was specific for elements.
Regardless. It's my browser. In my OS. On my machine. Let me decide.
Originally posted by c69:
OF COURSE, there must be an option to turn this of/off,
and of course there must be site preference for this - because, say, google docs, or youtube/soundcloud should NOT be suspended, while i'm reading other tabs
Originally posted by aliquis:
I wouldn't leave it up to the developers to decide.
Regardless. It's my browser. In my OS. On my machine. Let me decide.
Originally posted by aliquis:
Even if it broke AJAX pages it would be a users choice and expected.
Of course!
This should be a priority for Opera to implement.