How can I make my app load faster?

Any tips on making my app load faster? On an iPhone 4 the Default.png screen sits there for almost 5 seconds before showing anything from my app.

I try to load as much as I can later on as needed. What’s confusing is I barely load anything before showing the text “Loading…” yet once execution reaches that point everything after that loads so quickly you can barely see the message. That includes all images, sounds, sprites, they are all loaded after the loading text is shown.

Is there anything I can control during that initial load?

[import]uid: 82915 topic_id: 18856 reply_id: 318856[/import]

How big is your app?

That’s quite a long delay - maybe check mem usage on launch?

[lua]local function monitorMem(event)
collectgarbage(“collect”)

print( “\nMemUsage: " … (collectgarbage(“count”)/1000) … " MB”)
print("Texture Usage " … system.getInfo( “textureMemoryUsed” ) / 1000000)

return true
end

Runtime:addEventListener(“enterFrame”, monitorMem)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 18856 reply_id: 72613[/import]

The .lua code is 184 KB in 23 files
The code + assets is 32.2 MB
The .app bundle built for iPhone is 33.6 MB

Memory use after launch:
MemUsage: 0.2694384765625 MB
Texture Usage 76.120064
[import]uid: 82915 topic_id: 18856 reply_id: 72617[/import]

Woah! 76mb of texture memory! That’s pretty big I would say! [import]uid: 64174 topic_id: 18856 reply_id: 72618[/import]

Loading lots of big audio files can also be a bottleneck.

[import]uid: 7563 topic_id: 18856 reply_id: 72620[/import]

I will work on reducing the texture memory use, but the thing is here’s the results right when the application starts and I’ve loaded my basic framework code, but before I start on graphics and sound:

MemUsage: 0.1136005859375 MB
Texture Usage 1.114112

And that is after the 5 second app loading time on the device that I am trying to reduce.

Then I load a bunch of images and that texture memory shoots up, but that step happens really fast. What I’d like to know is why is the delay so long before a single image is even loaded? [import]uid: 82915 topic_id: 18856 reply_id: 72623[/import]

What are you doing in your code when the first scene is generated?
Anything in the backend? Checking for network or anything like that? [import]uid: 13859 topic_id: 18856 reply_id: 72645[/import]

Almost nothing is done before I call a function to show “Loading…” text on a black background. I’ve put any code that loads anything (images, sounds, sprites) in functions and I only call those functions at the end of Main.lua well after the loading screen should be displayed. I have no network code, no game center, no ads, no analytics, nothing of that sort.

I did make some progress reducing the loading time by reducing the file sizes of my audio and graphics and replacing some load sounds with load streams. What I don’t understand is why these changes affected the time Default.png is shown when all that loading is supposed to happen after my own loading screen is displayed.

I think I need to understand better what is happening under the hood when it comes to how Corona works. I mean regarding the details of when display code results in something being shown on the screen compared to further code being executed.

Any recommendations of where I should start reading?
[import]uid: 82915 topic_id: 18856 reply_id: 73103[/import]

Did you tried to use Director Class to first load menu and then from it call game file? [import]uid: 16142 topic_id: 18856 reply_id: 73107[/import]

Hey, @jadeonly, I’m not sure if this could help, but I’m planning on using “Load Progress Bar” from Ken Rogoway in code exchange:

http://developer.anscamobile.com/code/load-progress-bar

I haven’t gotten around to it (and therefore, I don’t really know how it works yet), but based on the description of it, I thought, maybe, it could help you out in some ways?

Naomi [import]uid: 67217 topic_id: 18856 reply_id: 73108[/import]

@Jade… Try moving those functions into a timer function. Corona won’t build and show your screen until the current linear code is complete.

I’m posting from my iphone, but for example:

… Your loading text call here

local timerFunc = function ()
DoSomething ()
Return true
End

timer.performWithDelay (1, timerFunc);

[import]uid: 13859 topic_id: 18856 reply_id: 73111[/import]

I did try putting everything that occurs after the loading screen into a timer delayed closure function. It did not change the time where Default.png is shown. Instead, it simply allowed my custom loading screen to be shown for whatever amount of time I set the delay to.

In other words, all the work that I expect to take time is put into a delayed function, yet adjusting that work does not have the expected result on the device. Instead of having my custom loading screen sit there, it only seems to affect the application load time before any code (Default.png).

I’m going to try replicating this in an application I can share with the community. It’s time consuming because you can only see the effect on the device so every change needs an ad-hoc build.

I might be able to do it today, I’ll be in touch. [import]uid: 82915 topic_id: 18856 reply_id: 73117[/import]