Breaking the 50% CPU limit in Flash

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Breaking the 50% CPU limit in Flash

Joe Dohn
Hey everyone,

I'm currently looking for a way to have Flash use more than 50% CPU. This is a limit that is present in Firefox 4 at least, maybe even in the standalone player. There are valid reasons to support the existence of such a limit.

But recently I stumbled upon this Alternativa3D demo: http://alternativaplatform.com/swf/demos/strategy/strategy.swf

More around and rotate the camera like a hobo on cracks while checking the Task Manager: This SWF can go up to 75% CPU.


What can be done to raise above 50%? I wouldn't mind the extra power at all... There are valid reasons to allow exceptions to that limit.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Alan Klement
while (true)
{
 addChild(new MovieClip());
}

:)

On Tue, Jun 21, 2011 at 12:29 PM, Joe Dohn <[hidden email]> wrote:
Hey everyone,

I'm currently looking for a way to have Flash use more than 50% CPU. This is a limit that is present in Firefox 4 at least, maybe even in the standalone player. There are valid reasons to support the existence of such a limit.

But recently I stumbled upon this Alternativa3D demo: http://alternativaplatform.com/swf/demos/strategy/strategy.swf

More around and rotate the camera like a hobo on cracks while checking the Task Manager: This SWF can go up to 75% CPU.


What can be done to raise above 50%? I wouldn't mind the extra power at all... There are valid reasons to allow exceptions to that limit.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Joe Dohn
Hehe nope, even this doesn't go above 50% CPU. Try it :)

I confirm the limit is also on standalone by the way.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Michael Cann
This is because flash is single threaded in the most part. So if you have a two core CPU you will only ever have a max of 50%. 

There are exceptions to this rule. Using Shader or ShaderJob (async) will user another thread, also the new image decoding library in flash 11 will use another thread. But apart from that you are stuck to the limit that a single of your cores can deliver.

Mike

On 21 June 2011 18:16, Joe Dohn <[hidden email]> wrote:
Hehe nope, even this doesn't go above 50% CPU. Try it :)

I confirm the limit is also on standalone by the way.

--
haXe - an open source web programming language
http://haxe.org



--
Mike Cann
http://www.mikecann.co.uk/
http://www.artificialgames.co.uk/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

MarcWeber
Excerpts from Michael Cann's message of Tue Jun 21 19:27:11 +0200 2011:
> single of your cores can deliver.

What about splitting and using two flash objects within a page? .. :)
I'm not that familiar with flash. But that looks like being the only
option then.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Justin Donaldson-3
Your other option would be to offload some calculation to javascript.  Haxe has some cool remoting capabilities for this:
http://haxe.org/doc/remoting/0_introduction

-Justin

On Tue, Jun 21, 2011 at 11:29 AM, Marc Weber <[hidden email]> wrote:
Excerpts from Michael Cann's message of Tue Jun 21 19:27:11 +0200 2011:
> single of your cores can deliver.

What about splitting and using two flash objects within a page? .. :)
I'm not that familiar with flash. But that looks like being the only
option then.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Michael Cann
What about splitting and using two flash objects within a page? .. :)

Yes I have considered this sort of hacky-flash threading for our facebook social game, but have never tried it. The problem would be communicating data between the instances at a descent speed. There are a few ways you could do this.
  •  Either via ExternalConnection using a JS bridge, but boxing and unboxing the data will be expensive. 
  • Via LocalConnection
  • Via localhost sockets
  • Via shared object, this will probably be slow due to the expense of flush()
Mike

On 21 June 2011 20:01, Justin Donaldson <[hidden email]> wrote:
Your other option would be to offload some calculation to javascript.  Haxe has some cool remoting capabilities for this:
http://haxe.org/doc/remoting/0_introduction

-Justin


On Tue, Jun 21, 2011 at 11:29 AM, Marc Weber <[hidden email]> wrote:
Excerpts from Michael Cann's message of Tue Jun 21 19:27:11 +0200 2011:
> single of your cores can deliver.

What about splitting and using two flash objects within a page? .. :)
I'm not that familiar with flash. But that looks like being the only
option then.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Mike Cann
http://www.mikecann.co.uk/
http://www.artificialgames.co.uk/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Joe Dohn
In reply to this post by MarcWeber
"This is because flash is single threaded in the most part. So if you have a two core CPU you will only ever have a max of 50%. "


This makes sense. I dismissed this hypothesis because the task manager shows that both of my cores are working, but I'm not sure how much that graph can be trusted.

Do you or anyone reading this have a CPU with more than two cores?
If so, the theory would be confirmed if Flash CPU usage caps at 100/NumberOfCores for you (i.e. 25% on a quad core CPU).


If Pixel Bender is the only solution to use more CPU within a single SWF, well...good to know but it sucks ^^

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Joe Dohn
In reply to this post by Michael Cann
Thanks for the workaround ideas, I'll keep that in mind :)

I do wonder if quad cores really do get stuck at 25% though. Before posting here I thought that the limit was made by Adobe on purpose.

But while a 50% cap is understandable considering how widespread Flash is on the web, 25% is unacceptable and if the theory confirms, it gets even lower the more cores you have.

I really hope Adobe is working on this seriously. Too bad haXe can't help on this issue.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Michael Cann
Yep, I have a quad core and you get 25% total CPU usage if you write a never-ending while loop. 

On 21 June 2011 20:24, Joe Dohn <[hidden email]> wrote:
Thanks for the workaround ideas, I'll keep that in mind :)

I do wonder if quad cores really do get stuck at 25% though. Before posting here I thought that the limit was made by Adobe on purpose.

But while a 50% cap is understandable considering how widespread Flash is on the web, 25% is unacceptable and if the theory confirms, it gets even lower the more cores you have.

I really hope Adobe is working on this seriously. Too bad haXe can't help on this issue.

--
haXe - an open source web programming language
http://haxe.org



--
Mike Cann
http://www.mikecann.co.uk/
http://www.artificialgames.co.uk/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Matthew Spencer-2
In reply to this post by MarcWeber

What about splitting and using two flash objects within a page? .. :)
I'm not that familiar with flash. But that looks like being the only
option then.
I tried this about a year ago using local connection to send data. Still only used a single thread. It's possible this has changed though. 

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Adrian Cowan
In reply to this post by Michael Cann

Is quite simple why this happens, you computer is shifting the load from that one process between multiple cores, the more cores the less it gets shared between them.

On Jun 22, 2011 5:46 AM, "Michael Cann" <[hidden email]> wrote:
> Yep, I have a quad core and you get 25% total CPU usage if you write a
> never-ending while loop.
>
> On 21 June 2011 20:24, Joe Dohn <[hidden email]> wrote:
>
>> Thanks for the workaround ideas, I'll keep that in mind :)
>>
>> I do wonder if quad cores really do get stuck at 25% though. Before posting
>> here I thought that the limit was made by Adobe on purpose.
>>
>> But while a 50% cap is understandable considering how widespread Flash is
>> on the web, 25% is unacceptable and if the theory confirms, it gets even
>> lower the more cores you have.
>>
>> I really hope Adobe is working on this seriously. Too bad haXe can't help
>> on this issue.
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
>
>
> --
> Mike Cann
> http://www.mikecann.co.uk/
> http://www.artificialgames.co.uk/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Breaking the 50% CPU limit in Flash

Joe Dohn
In reply to this post by Michael Cann
That settles it then. Thanks :)


Will Adobe ever address this or are we doomed to live with 5%- CPU when we'll have 20+ cores? O_o




--- On Tue, 6/21/11, Michael Cann <[hidden email]> wrote:

From: Michael Cann <[hidden email]>
Subject: Re: [haXe] Breaking the 50% CPU limit in Flash
To: "The haXe compiler list" <[hidden email]>
Date: Tuesday, June 21, 2011, 7:44 PM

Yep, I have a quad core and you get 25% total CPU usage if you write a never-ending while loop.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] Breaking the 50% CPU limit in Flash

Rob Fell

On 11:59 AM, Joe Dohn wrote:
> That settles it then. Thanks :)
>
>
> Will Adobe ever address this or are we doomed to live with 5%- CPU
> when we'll have 20+ cores? O_o
>
Hang in there!  If not already familiar, check out the Web Worker
approach in js and start planning your code design accordingly.

>
>
>
> --- On *Tue, 6/21/11, Michael Cann /<[hidden email]>/* wrote:
>
>
>     From: Michael Cann <[hidden email]>
>     Subject: Re: [haXe] Breaking the 50% CPU limit in Flash
>     To: "The haXe compiler list" <[hidden email]>
>     Date: Tuesday, June 21, 2011, 7:44 PM
>
>     Yep, I have a quad core and you get 25% total CPU usage if you
>     write a never-ending while loop.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] Breaking the 50% CPU limit in Flash

Michael Cann
Well this isnt an adobe problem strictly and rather a larger issue of parallel programming in general. 

Its difficult to parrellise a program, at what point do you split it? How do you handle race conditions and deadlocking? 

Sure Adobe should give us worker threads so we can perform our expensive jobs in them (and they have hinted many times that they are coming soon), but you are still going to have the difficult problem of working out where to split you program.

Mike

On 22 June 2011 20:08, Rob Fell <[hidden email]> wrote:

On 11:59 AM, Joe Dohn wrote:
That settles it then. Thanks :)


Will Adobe ever address this or are we doomed to live with 5%- CPU when we'll have 20+ cores? O_o

Hang in there!  If not already familiar, check out the Web Worker approach in js and start planning your code design accordingly.





--- On *Tue, 6/21/11, Michael Cann /<[hidden email]>/* wrote:


   From: Michael Cann <[hidden email]>
   Subject: Re: [haXe] Breaking the 50% CPU limit in Flash
   To: "The haXe compiler list" <[hidden email]>
   Date: Tuesday, June 21, 2011, 7:44 PM

   Yep, I have a quad core and you get 25% total CPU usage if you
   write a never-ending while loop.



--
haXe - an open source web programming language
http://haxe.org



--
Mike Cann
http://www.mikecann.co.uk/
http://www.artificialgames.co.uk/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] Breaking the 50% CPU limit in Flash

Joe Dohn
In reply to this post by Rob Fell
Nice, Web Workers is interesting stuff. Though it's in JavaScript, and others have said in this thread that having to communicate between Flash and JS could make the deal not worth it.


I was thinking, since Pixel Bender can use multi cores it should have access to a hook, right? Then, could Nicolas or someone skilled find it so that a future version of haXe is able to run code in separate processes/cores? A bit like how flash.Memory dug out the opcodes and exposed them.

Or is it not possible for X or Y reason?




--- On Wed, 6/22/11, Rob Fell <[hidden email]> wrote:

From: Rob Fell <[hidden email]>
Subject: Re: Re: [haXe] Breaking the 50% CPU limit in Flash
To: "The haXe compiler list" <[hidden email]>
Date: Wednesday, June 22, 2011, 7:08 PM

Hang in there!  If not already familiar, check out the Web Worker
approach in js and start planning your code design accordingly.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] Breaking the 50% CPU limit in Flash

laurence taylor
You can handle parallelism by specifying your program in Arrows and letting a scheduler handle thread execution. The benefit of this
approach is that there is no notational difference between an event based program, a single threaded program, a multithreaded program,
or one calling multiple remote components. /rant

regards,

Laurence

On Wed, Jun 22, 2011 at 9:28 PM, Joe Dohn <[hidden email]> wrote:
Nice, Web Workers is interesting stuff. Though it's in JavaScript, and others have said in this thread that having to communicate between Flash and JS could make the deal not worth it.


I was thinking, since Pixel Bender can use multi cores it should have access to a hook, right? Then, could Nicolas or someone skilled find it so that a future version of haXe is able to run code in separate processes/cores? A bit like how flash.Memory dug out the opcodes and exposed them.

Or is it not possible for X or Y reason?




--- On Wed, 6/22/11, Rob Fell <[hidden email]> wrote:

From: Rob Fell <[hidden email]>
Subject: Re: Re: [haXe] Breaking the 50% CPU limit in Flash

To: "The haXe compiler list" <[hidden email]>
Date: Wednesday, June 22, 2011, 7:08 PM


Hang in there!  If not already familiar, check out the Web Worker
approach in js and start planning your code design accordingly.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] Breaking the 50% CPU limit in Flash

Joe Dohn
In reply to this post by Michael Cann
Indeed. But I think I know how I'd do it, if Flash allowed me to. Although stuff always goes horribly wrong when you move from theory to concrete ;). Murphy's laws are the bane of me.


--- On Wed, 6/22/11, Michael Cann <[hidden email]> wrote:

From: Michael Cann <[hidden email]>
Subject: Re: Re: [haXe] Breaking the 50% CPU limit in Flash
To: "The haXe compiler list" <[hidden email]>
Date: Wednesday, June 22, 2011, 7:19 PM

Well this isnt an adobe problem strictly and rather a larger issue of parallel programming in general. 

Its difficult to parrellise a program, at what point do you split it? How do you handle race conditions and deadlocking? 

Sure Adobe should give us worker threads so we can perform our expensive jobs in them (and they have hinted many times that they are coming soon), but you are still going to have the difficult problem of working out where to split you program.

Mike

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: [haXe] Breaking the 50% CPU limit in Flash

Rob Fell
In reply to this post by Joe Dohn


On 11:59 AM, Joe Dohn wrote:
> Nice, Web Workers is interesting stuff. Though it's in JavaScript, and
> others have said in this thread that having to communicate between
> Flash and JS could make the deal not worth it.
>

Indeed such a Flash to JS bridge would just be a technical curio
compared to using dedicated API in your chosen platform(s).  Cough.

>
> I was thinking, since Pixel Bender can use multi cores it should have
> access to a hook, right? Then, could Nicolas or someone skilled find
> it so that a future version of haXe is able to run code in separate
> processes/cores? A bit like how flash.Memory dug out the opcodes and
> exposed them.
>
> Or is it not possible for X or Y reason?
>
>
>
>
> --- On *Wed, 6/22/11, Rob Fell /<[hidden email]>/* wrote:
>
>
>     From: Rob Fell <[hidden email]>
>     Subject: Re: Re: [haXe] Breaking the 50% CPU limit in Flash
>     To: "The haXe compiler list" <[hidden email]>
>     Date: Wednesday, June 22, 2011, 7:08 PM
>
>     Hang in there!  If not already familiar, check out the Web Worker
>     approach in js and start planning your code design accordingly.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] Breaking the 50% CPU limit in Flash

Raoul Duke
In reply to this post by laurence taylor
On Wed, Jun 22, 2011 at 12:36 PM, laurence taylor
<[hidden email]> wrote:
> You can handle parallelism by specifying your program in Arrows and letting a scheduler handle thread execution. The benefit of this
> approach is that there is no notational difference between an event based program, a single threaded program, a multithreaded program,
> or one calling multiple remote components. /rant

you're hired!

:-)

--
haXe - an open source web programming language
http://haxe.org
12