Hi,
my name is Alexandre, I’m finishing my first iPhone game but when I installed it on my iPhone to test how smooth it runs, I had the unpleasant surprise to see it’s really slow.
The menu screen is running perfectly fine, no lag, all ok.
When I hit start, it takes a long time to actually start (between 20~30sec), and when it starts, its too slow, not able to play at all.
I ran the Profiler to see what was going on, but I don’t know how to see the Memory Allocation that would happen on iPhone, only the allocation on the Mac itself… So I have no clue about what’s consuming this much on the iPhone.
I thought it might be caused by some scripts, but I tried disabling each and every script, one by one and testing, and again no change to performance.
Then I thought it could be the sprites (2d game), but as far as I know, Sprite Manager 2 is used to avoid this problem, and I have around 16 Drawcalls most of the times (but sometimes I noticed some anomalies on Profiler, like drawcalls suddenly becoming like -20193712 (a random huge negative number), and a few seconds later, it goes over 10 billion drawcalls/second (but again, even with that much drawcalls, the game ran smooth on Mac, so I thought it might be just a glitch on Profiler).
I already spent a couple of days trying to figure this out with researches but with no luck, so I decided to post it here.
Is there any information I need to provide so the problem can be traced?
edit: I compiled it first to 3.0.0 and then to 3.1.3, both had the same slowing problem.
How many tris/verts? It’s always a good idea to periodically test on the actual device throughout development, instead of waiting to get an unpleasant surprise near the end.
Never do any stability, system resource and performance test on the Mac (not even the simulator). Nothing will behave like the device and nothing beats using Instruments on the device if you are interested getting any reasonable information on performance, memory usage etc …
Hmm
had never heard of Instruments, going for it right now.
Eric, I’ll answer you as soon as I get to work, as I dont know it right now.
Thanks for the help!
That indeed helped, but I still run it a bit slow.
I ran Instrument as Object Alloc to see what was going on, and the #Overall increased in a huge speed, although the #Living remained stable.
Could this low performance be caused by a high creation rate on objects alloc and de-alloc?
whats your tri and vert count. and your drawcall count? might be a high drawcall. Not sure if theres an official figure, but i try to keep my games (well, one game i’ve finished so far) at around 20-30 draw calls, and it seems to work smoothly. Higher then that and it begins to suffer, however i usually have a very low tri/vert count.
20-30 is reqiured for pre 3GS, after 3GS its much harder to define as its a matter of balancing out drawcalls - vertices - physics - other cpu work (the 3GS+ have a much stronger cpu even though its clocking is only slightly higher the cpu itself is much more capable on that end)
I have the same problem with my 2d game and I just wrote a simple code , if you compile with Iphne you can easily see a framerate or flicker slow down please take a look as well…
Right now the game is running around these numbers:
Drawcalls: 16
Tris: 134
Verts: 148
But I just got a weird thing here…
The Tris, Verts and Used Textures dropped to 0 and the Drawcalls jumped to 20586084 and then stabilized back to the numbers above.
Thank you a lot for those who helped, but me and my boss managed to solve the problem here.
I used Sprite Manager generating 4 Sprite Atlases to make things cleaner and more organized, but I didnt know that by doing so, each draw call that would draw from a different material would have to switch material, draw, check material, switch if needed, draw again, check and so on…
So on every update it was switching materials between 4 of them.
Just by putting them all together on one material and optimizing GetComponent<>() calls solved everything (the materials part made the bigger difference)
Hmm
I just ran Instruments here to check for leaks and I found some leaks showing up.
How do I track them down in code level in order to fix them?
Researching it now, but any help is appreciated.
Thank you!
For some reason, just calling a GC.Collect() in a co-routine solved it, but please correct me if I am wrong (and I might be, as I`m trying to learn as much as possible here): isn’t Garbage Collector supposed to run periodically already?
What could cause it not to be as effective as it should be?