Closed KieranP closed 7 years ago
After some optimizations, I was able to decrease tick times from 0.107s down to 0.085s (see d30bb4531f4acafc7c413d1c669bbf0490412a12).
The bottlenecks still appear to be those foreach loops. But I cannot figure out why.
Notes on investigations as to why the PHP implementation is so slow.
Looks like the two foreach loops in the tick() function are the cause.
Attempt: Added timing code around the two foreach loops, and inside the loop, and then subtracting the time for the executed code inside the loop from the overall time around the loop.
Result: Shows that the loop itself (a simple iteration) is taking 0.139s in a 0.167s tick (a whopping 83.2% of the time). The question is, why is the foreach loop taking that long. A quick test shows a 'for' and 'while' blocks are just as slow.
Notes: The array size is 150*40 = 6000. Maybe PHP doesn't cope with large arrays?