A Flash Developer Resource Site

Page 4 of 21 FirstFirst 1234567814 ... LastLast
Results 61 to 80 of 411

Thread: Optimization Tips

  1. #61
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Pred:
    Sorry mate, I meant an actual Flash register as opposed to a "real" CPU one.
    I think the look-up time is greatly improved if a variable is declared as opposed to just shoved in there.

    I really need to read up on the swf file format and fire up FLASM. joy.

    AJ:
    A while loop is quicker than a for loop, the example loop you posted wasn't formed as well as it could have been, eg
    PHP Code:
    var i=(10/2)+1;  //Just for examples sake
    while (--i){
       
    doSomeThing();
       
    doSomeThing();

    Squize.

  2. #62
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    This get's more and more strange. Decaliring gobal varable as _global also seems to have a speed impact,
    Code:
    _global.MAX_VALUE = 39999;
    This must work in a similar way to the var for localised variables on a global level. So:
    Code:
    _global.MAX_VALUE = 39999;
    function loop() {
    	var z;
    	for (z=0; z<MAX_VALUE; z++) {
    		z += 1;
    	}
    }
    loop();
    Results in about 6%-8% increase over the fastest for loop method:
    1936 ms
    1917 ms
    1932 ms
    1923 ms
    1946 ms

    I hope this helps someone!!!

    RipX

  3. #63
    Senior Member D and J Media's Avatar
    Join Date
    Jan 2003
    Location
    NC, USA
    Posts
    300
    Originally posted by RipX

    I hope this helps someone!!!

    RipX

    Actually, yeah.

  4. #64
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    RipX could you post your timer code here so if anyone wants to test something they are doing it on an equal footing ?

    If you remember I asked about _global in the retro game thread and what sort of performance impact it may have. It'd be nice to have a definitive answer.

    I think the most important test would be using a global variable from within an mc. In theory it would eliminate all the _parent / _root ( And all the work-arounds ) calls. Now that would be cool.

    Squize.

  5. #65
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Sure, just a simple timer and trace:
    Code:
    _global.MAX_VALUE = 39999;
    function loop() {
    	var z;
    	var ms = getTimer();
    	trace("start test");
    	for (z=0; z<MAX_VALUE; z += 10) {
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    		z += 1;
    	}
    	trace("result : "+(getTimer()-ms)+" ms");
    }
    loop();
    Last edited by RipX; 04-15-2003 at 08:19 PM.

  6. #66
    Timetravelling Superhero AJ Infinity's Avatar
    Join Date
    Oct 2002
    Location
    The Realms of Infinity
    Posts
    203
    hmm, for loops execute pretty fast in C++ (that's what I was coding in at the moment, then checked my email and replied with that). Dang, Flash is freaking slow!

    RipX: Most of my main variables are globals.

    Anyway, back to playing WarCraft 3.
    From here to infinity,
    A J I N F I N I T Y

  7. #67
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Holy ****, just realised I was using z += 1 instead of z++

    This whips through at 604ms!!!! ouch

    Code:
    _global.MAX_VALUE = 39999;
    function loop() {
    	var z;
    	var ms = getTimer();
    	trace("start test");
    	for (z=0; z<MAX_VALUE; z += 10) {
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    	}
    	trace("result : "+(getTimer()-ms)+" ms");
    }
    loop();
    Edit - does help if I put the correct variable though - doh
    Code:
    _global.MAX_VALUE = 39999;
    function loop() {
    	var z;
    	var ms = getTimer();
    	trace("start test");
    	for (var i=0; i<MAX_VALUE; i += 10) {
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    		z++;
    	}
    	trace("result : "+(getTimer()-ms)+" ms");
    }
    loop();
    RipX
    Last edited by RipX; 04-15-2003 at 08:39 PM.

  8. #68
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    Suprise suprise:

    function loop() {
    var MAX_VALUE = 39999;
    var z;
    for (i=0; i<MAX_VALUE; i++) {
    z++;
    }
    }
    timer = getTimer();
    loop();
    trace(getTimer()-timer)

    is also faster (also you can see my state of the art timer)

  9. #69
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    I think this thread should be stickied.

    Mods?

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  10. #70
    Vox adityadennis's Avatar
    Join Date
    Apr 2001
    Posts
    751
    Wow!My first soon-to-be-stickied-if-all-goes-well-thread!

  11. #71
    ********* mentuat's Avatar
    Join Date
    Mar 2002
    Location
    out of office
    Posts
    717
    i concur, nail this to the top - it's the most constructive thread in a long time

  12. #72
    Junior Member
    Join Date
    May 2002
    Posts
    0
    i have a question, whats the diff between _root and _global, besides global seems to run faster?
    and is there a way to set where a fn is inside a mc, say i want it to be in root, other than using _root.loop = function() {} (since i found it slower than normal functions)

    am i making sense?

  13. #73
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    I think you mean prototypes, functions that can be used anywhere in the movie from what i can gather. The syntax is:

    MovieClip.prototype.myFunction = function(variables){
    }

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  14. #74
    Senior Member Kirill M.'s Avatar
    Join Date
    May 2002
    Location
    Toronto, Canada
    Posts
    711
    I think leif0's idea of moving several movie clips by putting enterFrame codes in them to do it themselves rather than putting them all into 1 container MC and moving that could have merit. I'm going through the process right now of putting the graphics into separate swfs so that the engine doesn't have the graphics built in. Because of this I have to use several container MC instead of 1 and I do see a bit of performance improvement. I'm not sure if having each MC move itself would be the best way, but having several container MC's instead of 1 does seem better.

  15. #75
    Junior Member
    Join Date
    May 2002
    Posts
    0
    first, why is it movieclip.prototye.mFn... what is the movieclip param for? i thought prototypes were fn's that could be accesed any where byt just doing mFn()

  16. #76
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    That is to declare the prototype, to access it you are right just use:

    myFunction();

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  17. #77
    Junior Member
    Join Date
    May 2002
    Posts
    0
    ok now question 2...

    i heard there isnt a differnce between function thingy () {} and thingy = function() {}, but is there a differnce between thingy = function() {} and mc.prototype.thingy = function() {} ?

  18. #78
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    A prototype differs from a function in that it is a method of a class, whereas a function is just a method.
    To put it simply, if you want a function "tied" to a specific class, eg the movieclip class or the color class then from a structured point of view you should use a prototype. This of course also applies to user defined classes.
    I guess it's down to how much you want to go down the OOP route. For the resource for prototypes check here: http://proto.layer51.com/default.aspx

    As to actual performance, I'm afraid someone else with more OOP experience will have to post. Also if you haven't got it already, try and get hold of Colin Moock's AS for Flash MX. It's the bible.

    Kirill M:
    I still can't see how that would figure out? My current game has 11x7 tiles on screen at a time, which are all held in a container MC. To have an enterFrame on 77 mc's would kill it, plus I imagine you'd get glitches were the screen is being updated where not all the mc's have moved.
    As to the using several container mc's and then using a movement handler (Like normal), I can't see how that would be quicker than a gotoAndStop scroller engine?
    Perhaps I'm just missing the point (More than likely) or for certain engines, ie push scrollers like Zelda, it may be better(?).

    Squize.

  19. #79
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Squize, when you keep talking about your project, are you talkin about colorworld? or a new game???

    RipX

  20. #80
    Junior Member
    Join Date
    May 2002
    Posts
    0
    sooo... prototypes (mc.prototype.fn = function(){}) are used is it is gonna be accesed alot, and can be accesed by fn() no matter where it is. and functions are like prototypes, but should be used if they are only gonna be accesed locally.

    right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center