Small example and does not respond

Hi.

I have one small problem.

Simple example:

local t = {} for q=1, 1000000 do t[#t+1] = q print(q) end

Corona stops at 2060 and does not respond. If 100000, then fine.

I can not understand why. How to fix it?

Thanks!

I just ran it and it went to 100,000 as expected, however it’s such a tight loop and with IO buffering, there were pauses where it looks like it stopped.

Are you on Windows or a Mac?

What version of Corona SDK are you using?

Rob

Windows 10 x64.

Corona last version (v2016.2949).

If 1.000.000, then Corona freezes, blocks, don`t respond. I waited 10 minutes, 30 minutes. Without changes.

Photo: https://drive.google.com/file/d/0B5q1p8d3Dw_tX0FNTHN3QV91TUU/view?usp=sharing

This is a simple example that shows a problem.

I write a game. I have a piece of code, where a lot loops. It is looking for options for level solutions.

When I ran the test on my Windows machine, I got to 18,353 before it decided that the app has stopped responding. I’ll bring this up with the Engineers, but the are going to point out, counting to a million it a tight loop like that isn’t a normal use case. Apps just don’t do that sort of thing.

If you need to initialize a million element array, try doing it without the print in side it. You don’t need a million lines in your console log. In fact, it’s the console log window that stopped by being flooded with messages and it can’t take a million prints in a fraction of a second. In fact you can test this yourself. Change your code to:

local t = {} for q=1, 1000000 do t[#t+1] = q end print("Hello, I'm done")

and see it work.

It work, But, the ploblem seems to a Corona or a Lua and my low pc.

I need to find all the solutions of levels. Record the result in a file and used in the game. Even without print, I have an error memory.

The algorithm is difficult. I will try to optimize it, or will use another language for this.

Thanks for help.

The suspect part maybe what you said about ‘record the result in a file’. Are you trying to do this line by line in the loop? That might be your problem.

I have a Corona app that loads 2.5 million data entries from a 26 megabyte text file, sorts them into 3 tables and then saves the results to file and it works perfectly, in seconds. But I’m saving my data as a whole after I’m done, rather than per entry.

I also wrote a genetic algorithm that’ll run tens of millions of populations and write them to file, cacheing them and then dumping them like 100 or 500 entries at a time to file.

So as you say, I think optimising your process is very much the key here, rather than any particular issue with corona or lua

As an alternative, what you can do is output the printed messages to Microsoft’s PowerShell via the following command line…

%windir%\system32\cmd.exe /c powershell -Command "& \"%CORONA\_SDK\_PATH%Corona Simulator.exe\" -no-console | echo"

What the above does is launch the Corona Simulator, telling it to not display Corona’s logging window, and have it redirect stdout to the PowerShell console instead.  And you can set up a desktop shortcut to run the above for your convenience.

Now, the reason the above will work for your situation is because it’ll shift the performance penalty to the Corona Simulator window.  That is, the Corona Simulator’s main UI thread will be *blocked* when the stdout buffer gets full while the PowerShell desperately tries to keep-up by *synchronously* echoing out the received messages.  Redirecting stdout to file like @JWiow suggested will work too because of the same reason; stdout is synchronously written to file, causing the simulator to block, shifting the performance penalty to the simulator.

Corona’s Win32 logging window is a bit different because it asynchronously receives all stdout messages, ensuring that the simulator’s stdout buffer never gets full, preventing it from blocking on the simulator side.  The advantage here is better performance when doing prints in Corona because the performance penalty is shifted over to the logging window instead.  So, this means that the simulator will be able to execute your long blocking for-loop print operation faster with our logging window versus outputting stdout to the PowerShell or to file.  This is what 99% of Corona developers want (most don’t do huge blocking operations like you’re doing).  Now, I’ll admit that Corona’s logging window shouldn’t block for as long as it does (it doesn’t block on me until I do over 10,000 prints in a single go), but my point being is that printing a huge amount of messages like this will incur a performance penalty in general and its more of a question of who eats the penalty.

Anyways, I hope this helps!

I just ran it and it went to 100,000 as expected, however it’s such a tight loop and with IO buffering, there were pauses where it looks like it stopped.

Are you on Windows or a Mac?

What version of Corona SDK are you using?

Rob

Windows 10 x64.

Corona last version (v2016.2949).

If 1.000.000, then Corona freezes, blocks, don`t respond. I waited 10 minutes, 30 minutes. Without changes.

Photo: https://drive.google.com/file/d/0B5q1p8d3Dw_tX0FNTHN3QV91TUU/view?usp=sharing

This is a simple example that shows a problem.

I write a game. I have a piece of code, where a lot loops. It is looking for options for level solutions.

When I ran the test on my Windows machine, I got to 18,353 before it decided that the app has stopped responding. I’ll bring this up with the Engineers, but the are going to point out, counting to a million it a tight loop like that isn’t a normal use case. Apps just don’t do that sort of thing.

If you need to initialize a million element array, try doing it without the print in side it. You don’t need a million lines in your console log. In fact, it’s the console log window that stopped by being flooded with messages and it can’t take a million prints in a fraction of a second. In fact you can test this yourself. Change your code to:

local t = {} for q=1, 1000000 do t[#t+1] = q end print("Hello, I'm done")

and see it work.

It work, But, the ploblem seems to a Corona or a Lua and my low pc.

I need to find all the solutions of levels. Record the result in a file and used in the game. Even without print, I have an error memory.

The algorithm is difficult. I will try to optimize it, or will use another language for this.

Thanks for help.

The suspect part maybe what you said about ‘record the result in a file’. Are you trying to do this line by line in the loop? That might be your problem.

I have a Corona app that loads 2.5 million data entries from a 26 megabyte text file, sorts them into 3 tables and then saves the results to file and it works perfectly, in seconds. But I’m saving my data as a whole after I’m done, rather than per entry.

I also wrote a genetic algorithm that’ll run tens of millions of populations and write them to file, cacheing them and then dumping them like 100 or 500 entries at a time to file.

So as you say, I think optimising your process is very much the key here, rather than any particular issue with corona or lua

As an alternative, what you can do is output the printed messages to Microsoft’s PowerShell via the following command line…

%windir%\system32\cmd.exe /c powershell -Command "& \"%CORONA\_SDK\_PATH%Corona Simulator.exe\" -no-console | echo"

What the above does is launch the Corona Simulator, telling it to not display Corona’s logging window, and have it redirect stdout to the PowerShell console instead.  And you can set up a desktop shortcut to run the above for your convenience.

Now, the reason the above will work for your situation is because it’ll shift the performance penalty to the Corona Simulator window.  That is, the Corona Simulator’s main UI thread will be *blocked* when the stdout buffer gets full while the PowerShell desperately tries to keep-up by *synchronously* echoing out the received messages.  Redirecting stdout to file like @JWiow suggested will work too because of the same reason; stdout is synchronously written to file, causing the simulator to block, shifting the performance penalty to the simulator.

Corona’s Win32 logging window is a bit different because it asynchronously receives all stdout messages, ensuring that the simulator’s stdout buffer never gets full, preventing it from blocking on the simulator side.  The advantage here is better performance when doing prints in Corona because the performance penalty is shifted over to the logging window instead.  So, this means that the simulator will be able to execute your long blocking for-loop print operation faster with our logging window versus outputting stdout to the PowerShell or to file.  This is what 99% of Corona developers want (most don’t do huge blocking operations like you’re doing).  Now, I’ll admit that Corona’s logging window shouldn’t block for as long as it does (it doesn’t block on me until I do over 10,000 prints in a single go), but my point being is that printing a huge amount of messages like this will incur a performance penalty in general and its more of a question of who eats the penalty.

Anyways, I hope this helps!