Skip to main content

App starting slowly

8 replies [Last post]
gruelfin
Offline
Joined: 2010-03-11
Points: 0

My application needs about 15 seconds to start! Is it possible that this is because i have about 30 (partly transparent) pictures in the resource file?

Is LWUIT slow with (transparent) images? and how can i resolve this issue?

Greetings and thanks in advance!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vimald
Offline
Joined: 2010-11-06
Points: 0

You have not mentioned anything about your midlet execution environment is it device / emulator? Or what is the size of your resource file ?

Either ways breakdown the issue into multiple checkpoints

  1. Use LWUIT logs in your code
  2. Check whether LWUIT display and themes are loaded successfully, determine this by putting logs before and after the below methods. Generally this statements are executed within seconds.
Display.init(...)

UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));

3) Now check the lwuit resource loading portion of your code, if it is the bottleneck read the excellent series of 'Places Demo' blog posts from Shai to optimize your resource file.

gruelfin
Offline
Joined: 2010-03-11
Points: 0

Hey thanks for your quick response. I did a few improvements on my code (everything i can think of), now the app starts in about 7 secs which i think is slow!

The resource file is about 4mb.

So i did following measures using ODD with a Nokia C-7 running Symbian^3 Anna:

Display.init(this); needs ~1100ms

UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0])); needs ~320ms

postMain() needs 10ms

Resources.open(resFile); needs 1ms

The image manipulation i do starts in the postMain, but as a Thread with low Priority, so i think the slow start cannot be caused by this

I did not touch onCreateMain() and beforeMain(Form f)

Do you think this is a normal startup time?? I think it's very slow! Do you or anyone else knows what i can try to make it faster?

Thanks in advance!

vimald
Offline
Joined: 2010-11-06
Points: 0

As per your timings, the cumulative time to load the LWUIT library (display and theme) is around 1.5 sec which is common, you cannot improve this further.

You have mentioned above that your resource file is around 4 MB which in my opinion is very very big, i think you need to look into your resource file

  • Discard redundant and unused graphics / animations in your resource file. Same goes for UI and themes in it.
  • If you have a multi-image graphic in resource file, make sure you have 0'ed the values for the resolutions that you dont instead to deploy on
  • Use OptiPng tool accessible via ResourceEditor to reduce the size of source graphics
  • If you have lot of animations, check the frame graphics in the timeline, see if you can substitue a frame by translating or transforming another frame within the animation. In this way the source graphics to build the animation is low.

In the meanwhile read this blog from Shai http://www.lwuit.com/2011/07/shrink-those-resources.html

gruelfin
Offline
Joined: 2010-03-11
Points: 0

Hello again, and thanks again for the quick answer!

The resource file is so big because i want to make a real time rotation of a partly transparent 850 kb .png file, depending on a
pointerDragged event.
Because the Image.rotate() function is so slow on not 90° rotations, i put 30x 3° (pre-)rotated images images in the resourcefile.
In a thread I load these images into an ImageArray, which takes 4 seconds, but this is not part of the slow loading because i
invoke this thread in postMain. Then i rotate these images with the Image.rotate() method in 90°, 180° and 270° steps, which is
very fast.
Real time movements of the picture are then made by loading the corresponding images. This was the only way to achieve "real time
rotation movement", because image.rotate is too slow with non 90° rotations.
I have used optiPng and it reduces the load time by one second to 6 seconds. Now i get in the range of an acceptable load time, but
i think it is still too much! I think there are no redundant or unused graphics and i don't use animations. I don't use multi image
because the app should only run on 360 x 640 pixel displays.
Is there anything else i can do?
Thank you very much for your helpful answers!
vprise
Offline
Joined: 2003-11-07
Points: 0

Put these images outside of the resource file in the jar and load them separately. We try not to pass the 500kb mark in a resource file since these files are loaded completely.

gruelfin
Offline
Joined: 2010-03-11
Points: 0

Great!

That reduced the starting time by another 2 seconds! Now the total starting time is 5 secs and then another 5 secs to load all the pictures (which i do in another thread, so the user does not notice!)

Thank you very much!

vimald
Offline
Joined: 2010-11-06
Points: 0

An experimental suggestion would be to start two concurrent threads in the startApp()

  1. In the first thread, aim to load, initial LWUIT and reach your main page.
  2. In the second concurrent thread, start a thread per 850 Kb image file and load each image file in its individual thread. Also put all your 850 Kb under '/res' folder and remove it from the resource editor (.res) file.

The idea is to load data from multiple smaller files rather than one big file and thus achieving better load time by concurrent processing of the data.

gruelfin
Offline
Joined: 2010-03-11
Points: 0

1.) I did this and it saved me seconds! Thank you!!

2.) If i start several concurrent threads, the threads themselves are faster when i count together the total execution time but the startup again gets slower!

Putting all files under the /res folder instead of the resources file saved me alot of time!

Thank you very much, this quest is solved unless someone has another idea =)

Greetings from Valencia, Spain