iOS Taking a screenshot doubles frame rate...

Coded Games

Member
Today I noticed a very strange behavior on my 2015 iPad Pro running iPadOS 13.

After playing the game for a while the frame rate will drop roughly in half. Checking the debug overlay the vast majority of this time is grey meaning "The time required to clear screen each draw step"

If I take a screenshot when these lag spikes occur performance will immediately return to normal. I took a couple videos showing this behavior. Has any of you experienced this before?

https://share.icloud.com/photos/0_gzvUTfTOK8CWfSIX-d3I0pQ#Lakewood_-_Oakbrook

https://share.icloud.com/photos/0LQrwmQBMfa4AUaRhSfMafnrQ
 

TheouAegis

Member
Does your surface count and/or texture page count change between when the slowdown starts and when the screenshot is taken?
 

Coded Games

Member
Does your surface count and/or texture page count change between when the slowdown starts and when the screenshot is taken?
I don't think so, the game can be literally paused. The first video shows that nothing should be happening. The texture swaps and vertex batches remain the same before and after screenshot.

Also, in general how am I supposed to reduce "The time required to clear screen each draw step"
 
G

GmlProgrammer

Guest
You can try to set it again to normal after the screenshot if that helps
 

Yal

🐧 *penguin noises*
GMC Elder
Wild guess: VRAM memory leak, a side effect of taking a screenshot is forcing a buffer flush and it leads to garbage-collecting the leaked resources. The skype-call performance boost might be for similar reasons (competing about resources leads to more flushes and GCs so the leaked resources get restored regularly).

Not sure how to force this to happen without side-effects, but some ideas...
  • Take a 1x1 pixel screenshot to the same filename regularly (might be possible if you alter the viewport outside of a draw event and then change it back right afterwards) - tricky to set up and wears out persistent memory in the device (usually MMC in embedded devices) but it's known-working
  • Turn off automatic drawing for 1 step, then turn it on again
  • Delete application_surface to force a rebuild of it
There's also draw_clear / draw_clear_alpha but I'm not sure if they force a screen clear or if they just draw a rectangle.
 

Coded Games

Member
Wild guess: VRAM memory leak, a side effect of taking a screenshot is forcing a buffer flush and it leads to garbage-collecting the leaked resources. The skype-call performance boost might be for similar reasons (competing about resources leads to more flushes and GCs so the leaked resources get restored regularly).

Not sure how to force this to happen without side-effects, but some ideas...

  • Take a 1x1 pixel screenshot to the same filename regularly (might be possible if you alter the viewport outside of a draw event and then change it back right afterwards) - tricky to set up and wears out persistent memory in the device (usually MMC in embedded devices) but it's known-working
  • Turn off automatic drawing for 1 step, then turn it on again
  • Delete application_surface to force a rebuild of it
There's also draw_clear / draw_clear_alpha but I'm not sure if they force a screen clear or if they just draw a rectangle.
Ok I’ll give some of these a try to see if they solve the problem. Do you think this is more a bug in GMS2, rather than a bug in my code? If that is the case I probably should file a bug report.

Edit: Is it possible to see VRAM usage in a game?
 
Last edited:

Coded Games

Member
Through further investigation it appears that the jumps in "time clearing the screen" only occur every other frame. That is why in the video it appears that the debug overlay is flashing. I'm not sure if that helps with anything. I used the debugger to monitor regular memory and there does not appear to be any memory leaks there. Unfortunately it does not seem like there is any way for me to monitor VRAM.
 
G

GmlProgrammer

Guest
Ok trying to get this thread back to its original topic.



I don’t know what you mean by “set it again to normal”
Ι mean, does it affect the room_speed or just the framerate? If it's the first case then you can set it again after the screenshot call
 

Mool

Member
I flush my VRAM at Android, after every room change. If the VRAM gets filled (with useless stuff) at android the games slows down alot (60->30 fps).

ALSO always delete surfaces, if you only need them for example every minute! If you store for example 2x8mb surfaces you will lose ~ 20 fps! Very insane. (android)

You can see this surface problem, if you enable the application surface. On low end phones the framerate will decrease a lot.

It isnt a GM bug
 
Last edited:

Coded Games

Member
Run the Task Manager, then click Performance. Then click GPU?
Unfortunately this is only happening on iOS, on my iPad. Does not happen on my phone which is a somewhat newer iPhone X. Unfortunately I don't think the Task Manager VRAM graph or its metrics are detailed enough to really tell if there is a VRAM leak. Only being able to see increments of 100 MBs kind of sucks. After playing the game for around 15 minutes my VRAM usage hovered around 0.8-1.1 GBs of my total 12 GBs. I usually can get the lag spikes on my iPad within 30 seconds so I don't really see an upward trend in VRAM usage. It kind of just increased and decreased depending on how much stuff was on the screen, which is what you would expect. After closing the game this dropped to about 0.6 GBs, so the game uses anywhere from 200 to 500 MBs of VRAM.

I also do not know how much VRAM my iPad has and I can't find it online so I could be running out.

Ι mean, does it affect the room_speed or just the framerate? If it's the first case then you can set it again after the screenshot call
Frame rate.

I flush my VRAM at Android, after every room change. If the VRAM gets filled (with useless stuff) at android the games slows down alot (60->30 fps).

ALSO always delete surfaces, if you only need them for example every minute! If you store for example 2x8mb surfaces you will lose ~ 20 fps! Very insane. (android)

You can see this surface problem, if you enable the application surface. On low end phones the framerate will decrease a lot.

It isnt a GM bug
The only thing in my entire game that uses surfaces is cards and I make sure to free their surfaces in the clean up event, after the cards are used. This is obvious, surfaces are just like all the other data structures and need to be manually freed from memory. So the majority of the time I have at most four 512x512 surfaces. These lag spikes can come and go even when no cards are in existence. Along with that, the lag doesn't correspond to the number of surfaces. I'll have 4 cards on the screen and have 30 FPS and then switch over to the deck view which has 50 cards and performance returns to 500 FPS. So I don't really think that it is the surfaces that are causing the problem.

Wild guess: VRAM memory leak, a side effect of taking a screenshot is forcing a buffer flush and it leads to garbage-collecting the leaked resources. The skype-call performance boost might be for similar reasons (competing about resources leads to more flushes and GCs so the leaked resources get restored regularly).

Not sure how to force this to happen without side-effects, but some ideas...
  • Take a 1x1 pixel screenshot to the same filename regularly (might be possible if you alter the viewport outside of a draw event and then change it back right afterwards) - tricky to set up and wears out persistent memory in the device (usually MMC in embedded devices) but it's known-working
  • Turn off automatic drawing for 1 step, then turn it on again
  • Delete application_surface to force a rebuild of it
There's also draw_clear / draw_clear_alpha but I'm not sure if they force a screen clear or if they just draw a rectangle.
I tried all three of your suggestions and none of them appear to have the same effect as physically taking a screenshot in iOS like I show in the video (pressing the home button and lock button at the same time).

I also tried building with YCC, originally I was just using the VM and that appears to have the same problem also.
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
Ah, I thought you took a screenshot in-game using screen_save. (I'm too lazy and paranoid to check any link that doesn't preview on the forum itself so I never watched the video). That changes the playing field a bit, the OS might do some bookkeeping when the screenshot app gets focus (I wouldn't be surprised if any button combination on any device that gets caught directly by the OS, like that screenshot combination, will be treated in similar style to Ctrl-Alt-Delete on Windows... including giving the OS focus temporarily, which might make the game enter some sort of sleep mode, even if it's so brief you don't even notice it, which when entering/leaving could cause some sort of resource garbage collecting).

...uhhhh, where was I going with this rant now again? Basically, it's the same theory I had before, except since it's an OS-only thing that caused the resource freeing, I've lost hope you can invoke it from in-game yourself (at least not in a way that won't disrupt the player's experience).
 
Top