Tunning loop performance!

Hi bros, i created very simple app to calculate something.
The logic is:
Input a number. Input a date.
From inputed nunber, convert to new number by *80%.
For the date, i compare between current date and inputed date to have number of different days.
After having those input parrameters, the calculation to reduce the number day by day with the formular number * ratio; ratio = 0.002 or 0.001 depends on how many different days between inputed date and current date.
My app working well with thunkable live. But on my iphone, It runs but doesn’t work, some attempts to click button then it unstable works but the return result is not correct as live.
so anyway to tunning, could you see my app in zip attachment file and advice me please.
Desktop.zip (863.3 KB)

Hi @anhtn0711oy, thanks for posting and welcome to the community! :wave:

One request. instead of an apk, can you provide a share link to the project?

Thanks Jared.
i found the reason is because of a large loop.
i tried to do very simple one and cannot run on iphone.
So with a project having large loop, is there another better way to do instead of using repeat while i > 20.000 do xxx

Potentially, @anhtn0711oy, I’ll check out your app sometime today/tomorrow and get back to you. There are others on here who are great with code optimization as well, maybe they will provide some input also! :slight_smile: i run some pretty big functions without slowing down my app. it depends on how it is called and looped i suppose.

Thanks so much Jared to spend time for me.
even i do not put any formula inside the loop, just increasing the loop element i,
it also makes the app very slow and cannot response the result on mobile device, on computer thunkable live, it’s running well, just need 2 second then response the result.
here is very simple blocks simulating the loop

Well. I mean. You put everything on hold to count to 15,000. Depending on the device, that may take a long time. It was about 1/2 second or less using an iPhone 11. It was almost instant when I executed the code using the method below

Also, when you use an app type variable, the speed is slower than that of a function type variable due to thunkable architecture.

See my example

Remix my example

Great, Thanks Jared so much.
well, i will find the way to convert some my loop to function type variables to speed it up.
this is my real first app

1 Like