Page tree
Skip to end of metadata
Go to start of metadata

This guide explains some code optimization advice to increase the performance of your application.

 

1. Avoid Dataset Commit

Do not commit a dataset unless it is required to store permanent data. It may cause excessive file operation which can be costly.

2. Avoid Dataset Auto Commit

Same as the dataset commit. Commit is executed whenever a column or row is changed by a single line of code change. The whole table is re-written to the database.

3. Use Less Image Stretch & Aspect Ratio

Image stretching and aspect ratio resizes image on the runtime. Image resizing sometimes is a costly operation. The best option is to use the normal mode and put images on the different image folders. For the network originated images, the best performance option is to request image with the most fitting size.

4. Use Less Linear & Flow layout changes

If a containing component is in a flow or linear layout, any size or position change on child objects causes recalculation of positions.

For example, a scroll view with 150 child objects. A change in first item causes repositioning of 149 items.

Linear or flow layout is also calculated during the start of the application . Therefore using this may also affect startup duration.

You can read more about layouts from the Layout  document.

5. Avoid Synchronous network requests

In a synchronous call, until the server request is received & processed or the server gives a time out whole application might hang for the waiting operation. This is not a good practice. Regardless of the size of the network transfer, the best practice is to avoid this.

6. Less Runtime changes

For example, a page contains 150 labels. The heights of those labels should be the same. After requiring changing the height of all of the labels, most common approach can be setting them all at once in the runtime. This will slow the performance. In detail, during the application start, properties of all objects are processed. Changing the property onShow event adjust the height of the object. This will cause setting the height of the label twice.

7. Use Non-image components

For the solid backgrounds, it is easy to use an image from the given visual design. However, it is not a good performance practice. In mobile environment, every performance gain counts. A single rectangle or a label performs better than a single image. Good practice would be, using a rectangle object, setting its background property of that color.

8. Less Dialog operations

Dialogs require more calculation than pages. When more than one dialog is open, those calculations are multiplied. Try not to use more than one dialog at once. Also try not to manipulate object positions and sizes at runtime which are contained in a dialog.

9. Less row-render operations

Row-render is triggered for every row in the repeatbox. Large blocks of code probably require more operation. This reduces rendering performance of a row. The best practice would be setting the dataset binding property for repeatbox and use that with the objects inside the repeatbox.

10. Hiding does not free memory

If an object using high resources (e.g. label with large text, image with large picture), hiding it or changing the page does not free the reserved memory for it. The best practice would be to assign that property to a low resource before hiding it.

11. Avoid Auto Size components

An object with auto size setting can change the size according to the child components or to the data. All auto size calculations cause UI layout change. This is a slow operation. If the size is known or can be calculated, the best practice would be setting it from code before runtime.

12. Avoid multiple getArray operations

Getting multiple values from the Smartface objects (such as Dataset.getColumnArray, or  Repeatbox.rows), performs calculations all the time and returns a new set of array. Whenever it is possible, the best practice would be after getting those values, they should be assigned to a variable and operations should be done by using that variable.

13. Avoid round edge

UI objects are based on rectangular objects. A round edge requires more operation to draw it on the UI. Normally, this is a fast operation but However, when it is used many times, such as in the repeatbox, during every new row-render, this operation is performed once again and this will cause reduction of the performance.

14. Avoid using reset

Resetting an object is a big operation. Every parameter is re-parsed from the compiled design and a layout operation is executed to set a basic property to its original state. The best practice would be to set these properties manually.

15. Avoid using integer parameter

We recommend you to use the string parameters instead of integer. Also, please use order of parameter instead of parameter name.

This will be slower:

this.drawLine({
	x1 : 10,
	y1 : 10,
	x2 : 50,
	y2 : 50,
	color : "#ff0000"
});

This will be faster:

this.drawLine(10, 10, 50, 50, 16711680);


16. Close GPS Connection

We recommend you to close GPS Connection when you get the location information. GPS connection slows down your Mobile device and it causes battery consumption.

Device.setGPSStatus(false);