performwithdelay wait for way too long

Hi, here a tough one

I’m dealing with an intermittent issue with performwithdelay, it seems that once in a while, it takes more time than expected, and I’m not talking about millisecond, I’m talking about between 2 and 4 second extra delay.

Context: I’m doing a board turn base game, and sometime, before you can play your next move, some events have to happen, Item appear on the board once in a while, enemy spawn, etc. 

I put print() statement all over my code so I could try to find where the lag occurred, because I know I could be the cause of this extra delay. I’ve been searching for a long time and now I am out of idea. The problem is that this issue happen intermittent. sometime in the early stage of the game, sometime not, etc. 

Here’s an simplified example:

local function someFunction() local delay = 2000 local loot = true print('promptLoot or updateBoard in ' .. delay) if loot then timer.performWithDelay(delay, promptLoot) else timer.performWithDelay(delay, updateBoard) end --[[  more code]]-- end local function updateBoard() print('update board') end local function promptLoot() print('promptLoot') end

The output will be:
 

12:00:00 \> promptLoot or updateBoard in 2000 12:00:04 \> promptLoot

so where does this extra 2 second come from? I know this isn’t all my code and It’s hard to tell. But what could delay my performwithdelay function so much?

is there anything like: the timer would start late because its a function called within a function called within a function, for example?

could it be that there is a mix between different timers?

could it be that I use too much memory  and memory texture that sometime, it cause a delay with performwithdelay?

We are at the last phase of making a great game but it won’t be great if there is a lag with performwithdelay.

if anybody have a hint, please let me know.

Also, what is an acceptable memory usage? is this too much?
>   memory = 1327kb and texture 34.6 ?

(i should mention that it lags on the simulator, on an android device and on an iphone6)

The fact that it lags on all devices and the simulator implies to me that something is happening that suddenly bogs down the game.

I’d suggest either profiling it: http://www.mydevelopersgames.com/profiler.html

Or verifying the bogging down with another tool.  If you have my “super meter” it should show a sudden spike during the times in question and the graph for that period will turn pink.  This indicates that something is causing the game to lag out for one or more frames.

rgmeter.png

If you don’t have the meter, please write me and I’ll send you a copy:  

** email address removed **

The meter won’t narrow the cause, but it will help confirm whether you’re getting some kind of hiccup in frames which is the culprit.  Next will be to find the cause of the hiccup.

Oh, and 1.4 MB of main memory usage is fine.  Is 34.6 KB or MB?  Either way, even 34.6 MB of video memory usage is no problem on almost all devices and definitely not a problem on modern devices.

@all,

Hi folks.  Some may be thinking, “Hey!  Ed gave that tool away for free.  I better e-mail him and ask for a copy too!”. 

I’m sorry to say, the answer will be, “No.”.  You’ll have to head over to Sellfy and spend the $3.

I offered it to jerars because this is the first post of his that I’ve read and it was well formatted, organized, and thought out.

This pleased me so much I thought, “Why not send a copy of the meter?”  I wanted to help of course, but I also want to encourage folks to put effort into making good forums posts.

Genius is never understood in it’s own time, Ed.

Thanks a lot RoamingGamer, this is very appreciated!
I’m trying your tool this morning and I’ll give you some feedback! :slight_smile:

(it was 34mb of memory texture, thanks for answering that one too)

The fact that it lags on all devices and the simulator implies to me that something is happening that suddenly bogs down the game.

I’d suggest either profiling it: http://www.mydevelopersgames.com/profiler.html

Or verifying the bogging down with another tool.  If you have my “super meter” it should show a sudden spike during the times in question and the graph for that period will turn pink.  This indicates that something is causing the game to lag out for one or more frames.

rgmeter.png

If you don’t have the meter, please write me and I’ll send you a copy:  

** email address removed **

The meter won’t narrow the cause, but it will help confirm whether you’re getting some kind of hiccup in frames which is the culprit.  Next will be to find the cause of the hiccup.

Oh, and 1.4 MB of main memory usage is fine.  Is 34.6 KB or MB?  Either way, even 34.6 MB of video memory usage is no problem on almost all devices and definitely not a problem on modern devices.

@all,

Hi folks.  Some may be thinking, “Hey!  Ed gave that tool away for free.  I better e-mail him and ask for a copy too!”. 

I’m sorry to say, the answer will be, “No.”.  You’ll have to head over to Sellfy and spend the $3.

I offered it to jerars because this is the first post of his that I’ve read and it was well formatted, organized, and thought out.

This pleased me so much I thought, “Why not send a copy of the meter?”  I wanted to help of course, but I also want to encourage folks to put effort into making good forums posts.

Genius is never understood in it’s own time, Ed.

Thanks a lot RoamingGamer, this is very appreciated!
I’m trying your tool this morning and I’ll give you some feedback! :slight_smile:

(it was 34mb of memory texture, thanks for answering that one too)