I’d come across a very funny bug the other day - while testing the lasers and explosions I destroyed a space station and about the same time ships started to spawn at a rapid rate. Several s second. A literal stream of ships.
I thought the issue was connected to me destroying the space station as I hadn’t intended to allow that (I just haven’t coded in the block yet as its convenient for testing) but I’d forgotten that an Anaconda can spawn a ship and what was actually happening was that a friendly trader was spawning in the area and it was, you guessed it, an Anaconda. The tactics routine for the Anaconda was still using the timings from the original game, which is based on loop executions, and I was running at 60fps - 60 runs throught the loop per second with a probability of spawn calibrated for a fraction of that speed… yeah lots of ships.
The fix was simple… adopt the same approach used in other tactics routines to not evaluate as frequently.
I did, however, get a fun sense of how much headroom their is in the code to maintain the frame rate. Answer: a lot. Left it running for ages and it continued to maintain its frame rate without dropping a beat. Modern JavaScript engines are really well optimised. There’s a video below.
I’ve also made the same tweak for ships launching from space stations as that was a bit mad too!