When developing MIDlet applications be aware that processors used in mobile phones are tipically 20-40 times slower than processor found in desktop computers. You should test your application on real devices (not only emulators) during development cycle to ensure that all modules execute fast enough. This short chapter lists all operations that are very slow, and gives you tips on how to make them faster.
Large data types
Working with large data types is slow. Large data types include: arrays, records, Image, Command, RecordStore, Http and Resource. To improve performance, you should reduce the number of variables of these types to minimum. If possible, use global variables of these types instead of local variables. The two following programs are identical; however, the second runs faster:
program prog1;
procedure menu;
var cmdQuit : command;
begin
cmdQuit := CreateCommand('Quit', CM_EXIT, 1);
AddCommand(cmdQuit);
repeat Delay(100); until GetClickedCommand() != EmptyCommand;
end;
begin
menu;
end. |
program prog2;
var cmdQuit : command;
procedure menu;
begin
cmdQuit := CreateCommand('Quit', CM_EXIT, 1);
AddCommand(cmdQuit);
repeat Delay(100); until GetClickedCommand() != EmptyCommand;
end;
begin
menu;
end. |
Using two-dimensional (or higher) arrays is also slow, so use them only when they are really necessary. If you really need two-dimensional arrays, make them global (instead of local) to improve performance.
Drawing
Drawing operations that draw into memory, such as DrawEllipse or DrawText are not slow. The operation that draws directly on to the device display, Repaint, is very slow operation. Be carefull to call Repaint only when you really need to update the device display.
Real numbers
Real number operations are slow because processors used in mobile phones do not have floating-point unit. Instead, MIDlets use software emulation which is slow. MIDletPascal offers two types of real number implementations: fixed-point and floating-point. Fixed-point arithemtic is faster than floating-point and requires less space in JAR file. Floating-point arithmetic is slower, takes more space in generated JAR file, but has better precision than fixed-point arithmetic. You can select the type of arithmetic in Build configurations dialog.
Accessing flash file system
The flash memory used in mobile phones is slow, so all operations that read or write from/to the flash memory suffer from it. Operations that access the flash file system are the record store operations and the resource operations. It is recommended that application reads all needeed data from the flash at startup, and saves its state on exit; while the application is running, it should not access the flash file system.
|