User Tag List

Results 1 to 6 of 6

Thread: Fast Loops vs Grouped Fast Loops vs ForEach

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Ryan's Avatar
    Join Date
    Nov 2008
    Location
    Australia
    Posts
    1,279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Fast Loops vs Grouped Fast Loops vs ForEach

    Anyone know how to get the best performance from Fast Loops?

    I read a lot of articles that said you should place your fast loops into a group, then enable it/disable it when you need it, otherwise MMF checks ALL fast loops within the application when it's running. Is this still the case or has it since been optimised?

    Also what's the verdict on Fast Loops vs ForEach object speed wise.

  2. #2
    Clicker Multimedia Fusion 2 DeveloperiOS Export Module
    Nifflas's Avatar
    Join Date
    Jul 2006
    Posts
    2,613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Fast Loops vs Grouped Fast Loops vs ForEach

    That's still the case, it's a good idea to use groups. ForEach is faster though; although it also checks all the "for each" conditions when triggered, there's two important differences.

    First, let's say you spread a value over 500 active objects, then loop through them. You'll need to run a fastloop 500 times, each time checking for which object that have the alterable value set to the loopindex. That requires 500 comparisons to filter all but the correct object. You'll end up with 250000 comparisons, and if you run the event every frame - 12500000 comparisons in one second. Saira was created before there were a ForEach object, and its main CPU usage is because of this.

    Second, when you use the ForEach object, you can put conditions in the event that triggers the ForEach, to only loop through the selected objects. You'll not have to loop through as many objects which is particularily useful when you're using many foreach conditions of the same kind.

  3. #3
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Fast Loops vs Grouped Fast Loops vs ForEach

    I'm considering rewriting a drastic amount of code with that in mind. Would be nice to replace all my object-filtering loops with foreach's to cut down the time complexity.

  4. #4
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Fast Loops vs Grouped Fast Loops vs ForEach

    I am actually curious on the scoping done by the ForEach object, as I've been mostly unfamiliar with it. When it iterates through a loop, each iteration simply scopes a single object, right? So applying further conditions should work with a linear time complexity (with respect to the loop), right?

    How does it work with nested fast loops- I know the stack frame does not preserve the object scope list (whether this is the 'proper' way to do it in MMF is dubious)- so would a fastloop inside a foreach reset the stack frame on return? What about a foreach in a foreach?


    I can really see a huge merit to replacing all my old objectdriven code with foreachs. I've mostly avoided it and done a lot of that in lua anyway- but it will certainly improve performance. But I'm still limited by that stupid fact that MMF2 can't create objects via expression (sigh, I have an entire subgroup of 50ish events to create different object types, inside an already O(n^3) loop. If the game wasn't paused while it executes anyway, my computer might asplode)





    But yeah @ OP- where possible, you should probably replace fast loops with ForEach calls during loops that need to iterate through objects. And by probably I mean really. But for loops that execute events not restricted by the object-scope list in complexity, it really shouldn't make a difference.

  5. #5
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, ┼rhus
    Posts
    3,457
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Re: Fast Loops vs Grouped Fast Loops vs ForEach

    Looping objects the old way is O(n^2) time complexity as it iterates each object once, but searching for that one object by picking it out based on the spread value is in itself linear time as well - henche N squared.

    Foreach does this in linear time by adding the looped objects to a list and then manually editing the selected objects list to contain only the one object you are interested in. This avoids all the object searching and picking so it is much faster.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Ryan's Avatar
    Join Date
    Nov 2008
    Location
    Australia
    Posts
    1,279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Fast Loops vs Grouped Fast Loops vs ForEach

    Yeah I'm considering replacing a lot of code as well. This might actually make my RTS engine viable with a large number of units.

    It's amazing that it's taken until now for someone to optimise object looping!

Similar Threads

  1. Fast Loops
    By Verbage in forum iOS Export Module Version 2.0
    Replies: 4
    Last Post: 12th April 2012, 03:07 PM
  2. fast loops
    By willow in forum Multimedia Fusion 2 - Technical Support
    Replies: 20
    Last Post: 11th November 2009, 12:00 AM
  3. I don't get Fast Loops, please help.
    By Carlos182 in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 12th September 2009, 08:43 AM
  4. Help with fast loops
    By BenMo in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 29th December 2006, 05:48 PM
  5. Fast loops
    By BenMo in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 19th December 2006, 09:13 PM

Posting Permissions

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