Optimization: Spawning vs. Preloading Actors

OK, I'm preparing to launch my first iPhone game on the iTunes store and I'm working on some optimization improvements. It's running OK for the most part, but on older models it slows down noticeably when there's too much happening on the screen and I was hoping to improve performance. I've been reading several threads about optimization and they've been helpful, but I have yet to find a solution that helps with my game.
Some quick background: My game is an enhanced space invaders-type game with waves of differing enemies coming on the screen, one wave (row) at a time. Once one wave is complete the next wave slides on screen and starts its decent. Each level has only a few waves.
In order to cut down on the number on spawns, all the waves start the game on the level, but off screen. Last night I spent a few hours making all my bullets recycle rather than spawn and destroy in the hopes that it would speed things up. It made things worse. It might have to do with the fact that I have several different ammo types and some of them fire faster than others, so I essentially added 22 new actors to the scene in order to recycle them. The old spawn and destroy method probably never had more than 8 or so of those actors on a level at once.
So, here is my primary question (but I snuck in two more):
1. Is having all the waves of enemies preloaded on the level slowing things down more than spawning only one wave at at time would? In some of my levels I have four waves of 6 enemies each. Since there's already a brief pause between waves I thought maybe it would be OK to spawn each new wave instead so there aren't up to 18 enemies (or more) waiting off screen, running code detection to see if they activate. Each enemy has a bit of code on it, but there are only 2 rules running on each until their wave is active.
2. I have a total of about 35 (including offscreen enemies) actors using transparent PNG on most levels. These actors are all fairly small (most are 28x40), but are this many transparent graphics slowing the game down?
Based on the advice from other threads I've tried to avoid behaviors like Constrain (only 1, maybe 2 uses of this per level) and Collide (though I still use overlap/collide checks on all my enemies and bullets). The game doesn't use any physics. I've been replacing some of the primary timers with self.time rules instead, but it doesn't seem to have made a difference in my case so far.
3. I've based this game off the very basic "Alien Conquerors" template and I use walls to detect when an enemy reach the end of the screen just like it does, but every once in a while an enemy slides through the wall (probably only when performance is dropping). I was thinking about turning on collision detection for the walls to keep this from happening, but would that make my performance worse since since collisions are going to happen a lot?
Sorry to run on a bit, but any insight would be very useful. This community has been very helpful, and I hope that if I can get the hang of GS a bit more, maybe I can become a helpful part of this community instead of just leeching off your collective wisdom.
Thanks.
Some quick background: My game is an enhanced space invaders-type game with waves of differing enemies coming on the screen, one wave (row) at a time. Once one wave is complete the next wave slides on screen and starts its decent. Each level has only a few waves.
In order to cut down on the number on spawns, all the waves start the game on the level, but off screen. Last night I spent a few hours making all my bullets recycle rather than spawn and destroy in the hopes that it would speed things up. It made things worse. It might have to do with the fact that I have several different ammo types and some of them fire faster than others, so I essentially added 22 new actors to the scene in order to recycle them. The old spawn and destroy method probably never had more than 8 or so of those actors on a level at once.
So, here is my primary question (but I snuck in two more):
1. Is having all the waves of enemies preloaded on the level slowing things down more than spawning only one wave at at time would? In some of my levels I have four waves of 6 enemies each. Since there's already a brief pause between waves I thought maybe it would be OK to spawn each new wave instead so there aren't up to 18 enemies (or more) waiting off screen, running code detection to see if they activate. Each enemy has a bit of code on it, but there are only 2 rules running on each until their wave is active.
2. I have a total of about 35 (including offscreen enemies) actors using transparent PNG on most levels. These actors are all fairly small (most are 28x40), but are this many transparent graphics slowing the game down?
Based on the advice from other threads I've tried to avoid behaviors like Constrain (only 1, maybe 2 uses of this per level) and Collide (though I still use overlap/collide checks on all my enemies and bullets). The game doesn't use any physics. I've been replacing some of the primary timers with self.time rules instead, but it doesn't seem to have made a difference in my case so far.
3. I've based this game off the very basic "Alien Conquerors" template and I use walls to detect when an enemy reach the end of the screen just like it does, but every once in a while an enemy slides through the wall (probably only when performance is dropping). I was thinking about turning on collision detection for the walls to keep this from happening, but would that make my performance worse since since collisions are going to happen a lot?
Sorry to run on a bit, but any insight would be very useful. This community has been very helpful, and I hope that if I can get the hang of GS a bit more, maybe I can become a helpful part of this community instead of just leeching off your collective wisdom.

Comments
1. I switched to a spawner and the performance increased dramatically. I'm sure the reason is that each enemy has a lot of rules, including the rules to detect when they should activate, and having them all start on the scene (even offscreen) was taxing the game. SInce I pause between waves anyway any processor hit is hardly noticed as I spawn each wave of enemies. It works very nice and opened up some other gameplay options as well.
2. Since the performance is strong now (as explained above) I don't think the graphics were/are a problem.
3. I still have occasional problems with this, but far fewer since the game has been optimized. I'm still not sure what to do with this. I suppose I'll turn on collision detection and see how it performs.
For example:
Wave 1 is finished - all enemies get reset to the default positions. Then when Wave 2 starts, the enemies change image and/or behave differently for that wave.
Then wave three starts and so on and so forth.
Essentially, lf each wave has say 7 actors, and only one wave is onscreen at once, you could have all the waves made up of 7 actors in total.
In one of my projects, I have about 10 or so enemies - they don't spawn, but come in from two different directions so there's about 10 enemies on screen at most at one time (this is more than enough!).
When wave 5 starts, the enemies change image. I'll be adding in different behaviour at some point too.
I should say I've only tried this out on iPad, but I've got 20 waves per level, and the enemies change every 4 levels. But there are only 10 enemies on screen ever, essentially filling in for four different enemy types.
That was my point I think!
I've not tried it with the new build yet though.
I'm rambling aren't I?
QS :O
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
----------
Can you give a link to those?
Shadows Peak is an atmospheric psychological horror that explores the dark side of a player.