Efficient Spawning

pHghostpHghost London, UKMember Posts: 2,342
I have a spawner (combined with a timer) spewing out tons of instances of an actor, one every 0.15 seconds. The instances are spawned offscreen and then shoot across the scene quite rapidly. I was wondering whether it would be more resource efficient to reduce the frequency of spawning, but spawn several at once, and space them out so that they still speed by in 0.15s intervals.

So, instead of:

every 0.15s
[
spawn actor, position (x) 0, relative to actor
]

it would be:

every 0.6s
[
spawn actor, position (x) 0, relative to actor
spawn actor, position (x) -100, relative to actor
spawn actor, position (x) -200, relative to actor
spawn actor, position (x) -300, relative to actor
]

Does it make any sense? Would it reduce the computing load? Or not much and isn't worth it?

Thanks!

Comments

  • UtopianGamesUtopianGames Member Posts: 5,692
    It's best to test on your device to see the FPS, have you thought about using particles if these actors don't have to interact?

    Darren.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    It would be more efficient to recycle them - as a game develops - things that were once fine - are now not - I have learned that with a game that has a lot going on. I just built the game with timers and spawns as a proof of concept but it soon became a huge resource hog. So on to the performance enhancement...

    That might be your path too. I just wanted to test gameplay and then think after that - performance!

    You can get performance gains using the game clock and recycling. There's heaps on these forums about that stuff too :)

    Cheers, M@
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    It would be more efficient to recycle them - as a game develops . . . .
    Every test I've ever done says this is a myth ! :ar! And every person who has made claims for recycling being less of a strain on resources (than spawn / destroy) has been unable to provide a project (even a small test project) that illustrates this !

    I've run long tests, projects that have run for hours spawning and destroying hundreds of thousands of actors, with absolutely no impact on performance, frame rate or memory usage.

    I think this used to be an issue for GameSalad, destroyed actors would not free up their memory, but this was dealt with years ago and now the 'recycle' myth, having entered GameSalad culture, persists. Of course I could be wrong (perhaps the issue has been reintroduced in a recent update ?), so if anyone has a project that shows recycling to be advantageous (or spawn/destroy to be problematic) I'd love to take a look at it.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    It would be more efficient to recycle them - as a game develops . . . .
    Every test I've ever done says this is a myth ! :ar! And every person who has made claims for recycling being less of a strain on resources (than spawn / destroy) has been unable to provide a project (even a small test project) that illustrates this !

    I've run long tests, projects that have run for hours spawning and destroying hundreds of thousands of actors, with absolutely no impact on performance, frame rate or memory usage.
    :-bd

    "this is a myth !" How dare you thay that… I am a mithter.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    It would be more efficient to recycle them - as a game develops . . . .
    Every test I've ever done says this is a myth ! :ar! And every person who has made claims for recycling being less of a strain on resources (than spawn / destroy) has been unable to provide a project (even a small test project) that illustrates this !

    I've run long tests, projects that have run for hours spawning and destroying hundreds of thousands of actors, with absolutely no impact on performance, frame rate or memory usage.
    :-bd

    "this is a myth !" How dare you thay that… I am a mithter.
    Have you been at the port again, you know it's still over a month 'till Christmas don't you.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2013

    Ha! :-$

    (I do like a good drop of port as it happens, and it's true I'll be having plenty of port over Christmas as we're spending Christmas and into the New Year in Portugal with my nephew and his Portuguese wife… the Portuguese like a drop of port, you know…)

    @pHghost Sorry for diverting your thread… :ar!

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    @pHghost Sorry for diverting your thread… :ar!
    Could a moderator move this to the Port and Fortified Wine sub-forum. ;)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    :))

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • pHghostpHghost London, UKMember Posts: 2,342
    edited November 2013
    :D

    @sadida172

    And which approach to spawning did you use, really small timer interval, or all at once and just changing the coordinates?

    To be clear, I don't have an issue with performance yet, but it is possible I will need several such spawners in each scene, so the amount of spawned actors might go MUCH higher than 40. So I wanted to know if there could be a difference, before I finish setting it all up, just so that I don't have to go back later to change it all. ;)

    @DeepBlueApps

    They do need to interact, though thanks for the tip, might come in handy for other elements.

    Thanks everyone!
  • natzuurnatzuur Member Posts: 304
    edited November 2013
    It would be more efficient to recycle them - as a game develops . . . .
    Every test I've ever done says this is a myth ! :ar! And every person who has made claims for recycling being less of a strain on resources (than spawn / destroy) has been unable to provide a project (even a small test project) that illustrates this !

    I've run long tests, projects that have run for hours spawning and destroying hundreds of thousands of actors, with absolutely no impact on performance, frame rate or memory usage.

    I think this used to be an issue for GameSalad, destroyed actors would not free up their memory, but this was dealt with years ago and now the 'recycle' myth, having entered GameSalad culture, persists. Of course I could be wrong (perhaps the issue has been reintroduced in a recent update ?), so if anyone has a project that shows recycling to be advantageous (or spawn/destroy to be problematic) I'd love to take a look at it.
    This. I have found spawning to be more efficient in some cases. For example, a staggered load to reduce load times ( like a pause menu that has multiple menus, but spawns the menus instead of them existing on the scene and being pre-loaded.)

    Also spawning multiple at once isn't much of an issue up to a certain point. (upwards of 25 at once is fine, 500 is not depending on the life of the actor).
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @Socks has every test you have done, been with real game scenarios? Where actors have a lot of rules and and constrains and artwork?

    My spacey game game was skipping frames as it's really quite full on with a lot of actors buzzing around firing off missiles mines and homing missiles and a ship that clones and fires bullets out at a rapid rate.

    The project ran smooth as with a few actors, and lots of instances and spawning them and destroying them so there was heaps going on and it was just GS boxes - not artwork - my proof of concept was complete and running smooth as butter.

    So then I started creating all the artwork and and putting in space effects and animations - a lot of unique sounds and wave formation delivery systems and buzzing patterns with cos sin equations.

    Suddenly my game started to stutter - not everything - just the odd actor - and this is in the viewer and on my iPhone 5.

    I had just done this with timers and spawns and destroys.

    So I replaced the timers with clock based rules. This gave an improvement straight away but I was still not happy with some things still skipping frames.

    I also recycled the aliens instead of spawning and destroying. Now perfect apart from one pesky creature.

    Finally I refined the equations to remove one constrain attribute.

    As a performance test what I like to do is run my games on my iPhone 3GS and 4 etc.

    The original timers and spawners game concept with hardly any artwork, and aliens as GameSalad boxes, runs way worse than my latest full game with all the artwork, sounds and animations.

    Simple prototype runs worse than full game? Wow.

    I really would be interested to see what the key items of performance enhancement are.

    Somebody could create a serious benchmarking tool ;)

    The game is still spawning lots of things - don't get me wrong - it's spawning like salmon.

    But the thing that made the game run smooth was clock timers, recycling and equation refinements.

    What are your thoughts on this?

    Cheers, M@
  • SocksSocks London, UK.Member Posts: 12,822
    @Socks has every test you have done, been with real game scenarios? Where actors have a lot of rules and and constrains and artwork?
    With all things being equal / if in all other ways the two situations are the same or similar then recycling seems to offer no advantages over Spawn/Destroy.
    What are your thoughts on this?
    To be honest there are too many factors involved for me to say anything really.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Cool @socks, always interesting to hear things like this - learning every day - cheers, M@
  • natzuurnatzuur Member Posts: 304
    edited November 2013
    The only difference I can think of is this:

    Spawning actors means the images for the actors are being loaded in real time. So 50 unique imaged actors with 2048 textures are likely to cause a hiccup in fps.

    Pre-loading (on scene from start) and recycling actors means the images are loaded in memory before the scene executes. So this adds to the load time, however once loaded it will be smoother while playing because of not needing to load those images during run time.

    However in most cases recycling was done on actors that are similar or the same in nature and don't have unique images or rulesets and are generally small (bullets), and would cause very little in terms of real time performance, hence why spawning is generally a better system for the sake of easiness and load times.

    But as you can see this isn't always the case and recycling has it's place too.

    A good metric for "benchmarking" would be Xcode tools running core animations and memory usage. You can see the benefits of both systems as outlined above and create some test projects to see.

    Also is your not destroying the actors fast enough, you will be getting a larger number of actors on the scene then if recycled and more actors=lower performance, so make sure the spawn and destroy are efficient.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    What I do is actually spawn, then recycle - that ended up being a lot more efficient and easier to manage.

    Thanks for all this - will look in to the Xcode side.... cheers, M@
Sign In or Register to comment.