Stop execution of javascript and plugins in background tabs

Forums » Opera for Windows/Mac/Linux » Desktop wish-list

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

3. June 2012, 10:25:36

hochmartinez

Posts: 18

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.

3. June 2012, 11:04:49

serious

Lab mouse and likes it!

Posts: 5313

-1, as this has big potential to break a lot of pages (eg. because they do some ajax polling or whatnot).

The W3C is working on the Page Visibility API for exactly that purpose.
All my posts only represent my own opinions.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]

4. June 2012, 10:55:03

hochmartinez

Posts: 18

Serious,

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

4. June 2012, 14:17:52

burnout426

Posts: 12532

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.

7. June 2012, 22:44:40

hochmartinez

Posts: 18

Hi,

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! :-)



8. June 2012, 10:23:57

serious

Lab mouse and likes it!

Posts: 5313

Originally posted by hochmartinez:

You can't break a process (program) or thread if you just pause it.

You never heard of things like race conditions, keep alive, or timeouts, did you?

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.
All my posts only represent my own opinions.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]

8. June 2012, 14:18:33 (edited)

hochmartinez

Posts: 18

Serious,

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! smile

8. June 2012, 17:28:56

serious

Lab mouse and likes it!

Posts: 5313

Originally posted by hochmartinez:

2. Keepalive and timeouts are used *during* the connection between a client and a server, in that case (Opera) and the HTTP Server.

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.

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.
All my posts only represent my own opinions.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]

8. June 2012, 17:30:25

RyanChappelle

NonOperator^=

Posts: 397

+1 for the feature to pause (not stop) script and plugin execution in background tabs. I guess to make it sane it should be enabled as either a per-tab or per-site preference.
My Wishlist:
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

8. June 2012, 18:50:14

serious

Lab mouse and likes it!

Posts: 5313

Originally posted by RyanChappelle:

for the feature to pause (not stop)

what would be the difference?
All my posts only represent my own opinions.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]

9. June 2012, 00:25:08

RyanChappelle

NonOperator^=

Posts: 397

Difference between pause and stop? You can resume from pause (it's sorta a saved state), stopping script execution would imply data and state loss I guess. There are things that simply do not need to happen in the background like redrawing / repainting, file I/O (way a too open avenue for privacy violations), or keyboard capture, but if a script was loading or populating a newsflash /newsbanner when it was paused, there's no reason why it can't resume loading or presenting right off the bat.

My Wishlist:
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

9. June 2012, 15:44:33

hochmartinez

Posts: 18

Serious,

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! smile

9. June 2012, 18:01:22

serious

Lab mouse and likes it!

Posts: 5313

maybe it's because of my job (sw tester), but I have developed a good eye for spotting the "shit can go wrong there" situations ... so maybe that explains my attitude wink
All my posts only represent my own opinions.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]

10. June 2012, 13:12:19

hochmartinez

Posts: 18

I'm sure you are a terrific tester! smile

Happy browsing smile

29. August 2012, 12:50:34

peeebo

Posts: 2

It seems this thread is dead.
Yet it I think it's a great idea. I often have plenty of tabs opened and always get annoyed by high cpu usage.
Maybe this could be achieved with an extension?

29. August 2012, 13:45:13

albuemil

Posts: 71

I was going to give it a +1 for saving CPU cycles, but then i realized i also have to give it a -1 since I use a lot of tabs that update without me actually watching them.

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.

22. September 2012, 09:47:48

aliquis

Posts: 9

Even if it broke AJAX pages it would be a users choice and expected.

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.

30. September 2012, 15:09:34

c69

Posts: 353

+1, who needs those dumb mandatory auto-updates for stock tickers, ads and website analytics ?
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 wink

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 wink Tip: your app or tab will just get closed.

30. October 2012, 06:38:28

aliquis

Posts: 9

So Opera has used up all my RAM, and half of the swap space I've allocated ON MY USB FLASH DRIVE where drive usage use up all CPU.

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!

5. November 2012, 07:27:49

iWasHere

Posts: 202

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

5. November 2012, 08:11:21

aliquis

Posts: 9

Originally posted by iWasHere:

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

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.

I would be ok with holding the data if it could be swapped of rather than held in RAM.

5. November 2012, 09:49:02

serious

Lab mouse and likes it!

Posts: 5313

as I already pointed out, that's the whole point of the page visibility api
All my posts only represent my own opinions.
[ Tweedo Monitor - Deluxe Website & Service Monitoring ]

5. December 2012, 03:11:10

timeroot

Posts: 3

Gonna seriously +1 this. This would be really nice.

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.

8. December 2012, 17:28:04

aliquis

Posts: 9

I wouldn't leave it up to the developers to decide.

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.

9. December 2012, 21:21:19

drozdman

Posts: 241

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 wink



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.

Forums » Opera for Windows/Mac/Linux » Desktop wish-list