Framerate drops are a huge problem on the Galaxy S4

Hello Forums!

I am relatively new to the Corona SDK, but finished up on my first game and I am running into an issue with framerate drops.  At first I thought it was my code, so I spent several weekends cleaning it up and re-writing it with to no avail.  I added the following code to my project to get a printout of the frame rate:

local runtime = 0

local function getDeltaTime()

   local temp = system.getTimer()  --Get current game time in ms

   local dt = (temp-runtime) / (1000/60)  --60fps or 30fps as base

   runtime = temp  --Store game time

   return dt

end

When I added the print out I was getting a drop to .40 or .36 about every 10 lines the rest of the time it was staying between .90 and 1.10.  I think this is causing jittery transitions in my objects, but it is really bad on the S4 in comparison to the S3 or S5.  I got a bit frustrated and decided to make a new project (Physics Based Game) and add this code to get a base line, and I was surprised when I got the same issue.

I am using a Windows 7 64bit machine, and updated to the latest Corona daily build.  Is this an issue with Corona?  Could it be a Bug of some sort?

Any insight would be appreciated!

Hi @irish.curse.on.steam,

Welcome to Corona. If you added simply this code (and virtually notihng else) to a new project, and the S4 is getting framerate drops, then that is mysterious. However, if you added this code to a project with many other aspects, there could be any number of issues causing the framerate drop, and we cannot know what the cause is.

If you can reproduce the issue with one of the Corona sample projects, then please post back your results and which project, otherwise this seems like another issue in your code (not the code posted above but somewhere else).

Best regards,

Brent

Hi Brent,

Thank you for your response.  To answer your question, if I open the Corona Simulator and do New Project => Physics Based Game and add the code above plus a print (dt) and Runtime:addEventListener( “enterFrame”, getDeltaTime ) in the main.lua and change the fps to 60 in the config there are large fluctuations in the printed values. If I understand how this code functions correctly these values should stay around 1.  Just running the newly created project gives me some serious differences.

1.2

0.96

0.6

0.66

0.06

0.84

0.96

1.14

0.72

0.84

1.2

1.2

0.36

1.08

That is just a sample of the print out. 

I am not sure what to think about this situation, I am seeing the same basic numbers in my game as well.

Thanks again

Just a suggestion, look in the SampleCode/Animation/SpriteTiles sample app and grab the code at the bottom to calculate your FPS and see how that goes.  It should give a real number like 59.02 fps as opposed to your fractions which is harder for people to understand.

Next, consider that if your frame rate is good on the S3 and S5 but not the S4, its possible you have other things going on that device depending on OS versions, CPU/GPU performance, background tasks running.  Just as an example my Google Nexus 7 used to run pretty well. Then along came Lollypop and I bet on that device my framerate would be all over the place now, with the only change being an OS upgrade.

Finally, we haven’t seen your code to see if there are things that can be optimized there. There are couple of other threads around jittery transitions active in the forums right now:
 

https://forums.coronalabs.com/topic/56242-objects-look-jittery-with-simple-physics/

https://forums.coronalabs.com/topic/56853-stuttering-when-moving-display-objects-across-screen/

Though these problems would be more apparent across multiple devices and would be worse on older devices.  What OS versions are you running on each device?

Rob

Thanks Rob,

Quick question about the code in the SampleCode/Animation/SpriteTiles sample app. I added it to a New Project Physics Based Game and ran in the simulator to check it out… seems like it fluctuates pretty rapidly between 27 and 33 which I am guessing is normal?  But when I change the config file to 60fps all heck breaks loose… its between 50 and 100. 

Is there a change that I need to make to that code to have it work at 60fps?

Thanks again

I did this:

local physics = require( "physics" ) physics.start() -- display ball image local ball = display.newImage( "Icon.png" ) ball.x = 145; ball.y = 200 -- add physics to the ball physics.addBody ( ball, { friction=0.5, bounce=2 } ) local prevTime = system.getTimer() local fps = display.newText( "30", 30, 47, nil, 24 ) fps:setFillColor( 1 ) fps.prevTime = prevTime local function enterFrame( event ) local curTime = event.time local dt = curTime - prevTime prevTime = curTime if ( (curTime - fps.prevTime ) \> 100 ) then -- limit how often fps updates fps.text = string.format( '%.2f', 1000 / dt ) end end Runtime:addEventListener( "enterFrame", enterFrame )

And I’m getting normal 50-60 fps results.

Rob

Rob, 

I copied your code above pasted into a blank main.lua. I put the the main.lua, icon.png, build settings, and config.lua into a folder and ran it in the simullator.  My result is still 50 - 100…

Thanks

Can we see your config.lua and build.settings?

Rob

Let me test it on Windows.

Rob

Config:

application = {
    content = {
        width = 320,
        height = 480,
        scale = “letterBox”,
        fps = 60,
        
        --[[
        imageSuffix = {
            ["@2x"] = 2,
        }
        --]]
    },

    --[[
    – Push notifications

    notification =
    {
        iphone =
        {
            types =
            {
                “badge”, “sound”, “alert”, “newsstand”
            }
        }
    }
    --]]    
}
 

Build:

– Supported values for orientation:
– portrait, portraitUpsideDown, landscapeLeft, landscapeRight

settings = {
    
    orientation = {
        default = “portrait”,
        supported = { “portrait”, }
    },
    
    iphone = {
        plist = {
            UIStatusBarHidden = false,
            UIPrerenderedIcon = true, – set to false for “shine” overlay
            --UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend

            --[[
            – iOS app URL schemes:
            CFBundleURLTypes =
            {
                {
                    CFBundleURLSchemes =
                    {
                        “fbXXXXXXXXXXXXXX”, – example scheme for facebook
                        “coronasdkapp”, – example second scheme
                    }
                }
            }
            --]]
        }
    },
    
    --[[
    – Android permissions

    androidPermissions = {
          “android.permission.INTERNET”,
      },

    ]]–
}
 

Thanks again

Just adding to talk.  I just tested this on my Windows machine and both 30 and 60 FPS are close to their respective values (slight deviations of less than 1 FPS).

I ran with the latest build: 2015.2646 (and 2015.2644 before I updated).

Questions:

  • What version of Corona are  you running?
  • What video card are you running?
  • Have you checked that your driver is up-to-date?
  • If you run task manager, how does your CPU usage and memory usage look?
  • Got any background processes (Virus scanners, other heavy hitters?) or is your machine idle during the tests?
  • How much memory and what CPU + Freq?  (Probably not the issue, but checking anyways)

Some of these questions are just me throwing stuff at the wall, hoping something sticks.

Hi roaminggamer,

I have tested this on 2 seperate Windows 7 64bit computers.

What version of Corona are  you running?

Tested on v2014.2511 and 2015.2642 on both machines

What video card are you running?

1st PC MSI Nvidia GTX 760  2nd PC AMD Radeon HD 5450

Have you checked that your driver is up-to-date?

Both are up to date and not on beta

If you run task manager, how does your CPU usage and memory usage look?

Both machines run at minimal (5 - 7 %) CPU Usage and 20 - 28 % physical memory.

Got any background processes (Virus scanners, other heavy hitters?) or is your machine idle during the tests?

happens if Virus scanners are enabled or disabled

How much memory and what CPU + Freq?  (Probably not the issue, but checking anyways)

1st PC

Intel Core i5 3.3GHz

8Gb DDR3 1600

2nd PC

Intel Core i3 3.30GHz

12Gb DDR3 1333

Thanks!

Well I think we are chasing a red herring here.  What we need to be determining is why the framerate is dropping on the S4.   We are in the middle of testing all our samples right now and no one is reporting  performance problems on the S4 that I am aware of. 

Lets get back to focusing on the S4 issues.  What happens if you build SpriteTiles for your S4?

Rob

Sorry the the side-track there.   :wacko:   I thought maybe this was being seen in the simulator and on the device.  

Cheers,

Ed

Ed,

It is being seen in the simulator as well.  The interesting thing is that today when I was getting ready to build the sprit tiles project the jump from 50 to 100 has stopped in the simulator on my home PC which is where I noticed it last night.  However, it is still spazzing out every few seconds.  Really high and low frame rates then just smooths out to 60 plus or minus a few.  I will be interested to see what it does on my work computer tomorrow. 

Anyway, I have the sprite tiles built at 30 and 60 fps but I do not have my phone with me.  I will update the thread when I have the results.

Thanks again!

Rob

The SpriteTiles at 30fps is pretty stable… at 60fps it is also pretty stable exept for around every 5 seconds it has a bit of a jump and drop. 

Evidently the simulator still has issues with this when going to 60fps, but knowing the simulator has this issue vs hardware makes me feel a little better moving forward. 

To top things off I reinstalled the game on the S4 without changing any of my code and it is a lot more stable. Confusing…  but I guess that comes with the territory.

Thanks again

Hi @irish.curse.on.steam,

Welcome to Corona. If you added simply this code (and virtually notihng else) to a new project, and the S4 is getting framerate drops, then that is mysterious. However, if you added this code to a project with many other aspects, there could be any number of issues causing the framerate drop, and we cannot know what the cause is.

If you can reproduce the issue with one of the Corona sample projects, then please post back your results and which project, otherwise this seems like another issue in your code (not the code posted above but somewhere else).

Best regards,

Brent

Hi Brent,

Thank you for your response.  To answer your question, if I open the Corona Simulator and do New Project => Physics Based Game and add the code above plus a print (dt) and Runtime:addEventListener( “enterFrame”, getDeltaTime ) in the main.lua and change the fps to 60 in the config there are large fluctuations in the printed values. If I understand how this code functions correctly these values should stay around 1.  Just running the newly created project gives me some serious differences.

1.2

0.96

0.6

0.66

0.06

0.84

0.96

1.14

0.72

0.84

1.2

1.2

0.36

1.08

That is just a sample of the print out. 

I am not sure what to think about this situation, I am seeing the same basic numbers in my game as well.

Thanks again

Just a suggestion, look in the SampleCode/Animation/SpriteTiles sample app and grab the code at the bottom to calculate your FPS and see how that goes.  It should give a real number like 59.02 fps as opposed to your fractions which is harder for people to understand.

Next, consider that if your frame rate is good on the S3 and S5 but not the S4, its possible you have other things going on that device depending on OS versions, CPU/GPU performance, background tasks running.  Just as an example my Google Nexus 7 used to run pretty well. Then along came Lollypop and I bet on that device my framerate would be all over the place now, with the only change being an OS upgrade.

Finally, we haven’t seen your code to see if there are things that can be optimized there. There are couple of other threads around jittery transitions active in the forums right now:
 

https://forums.coronalabs.com/topic/56242-objects-look-jittery-with-simple-physics/

https://forums.coronalabs.com/topic/56853-stuttering-when-moving-display-objects-across-screen/

Though these problems would be more apparent across multiple devices and would be worse on older devices.  What OS versions are you running on each device?

Rob

Thanks Rob,

Quick question about the code in the SampleCode/Animation/SpriteTiles sample app. I added it to a New Project Physics Based Game and ran in the simulator to check it out… seems like it fluctuates pretty rapidly between 27 and 33 which I am guessing is normal?  But when I change the config file to 60fps all heck breaks loose… its between 50 and 100. 

Is there a change that I need to make to that code to have it work at 60fps?

Thanks again