Performance Best Practices

A view in my application is slow to load the data displayed. Where do I begin in improving the performance?

The best place to start is to examine the queries being called in the init() function of the view. If the query is filtering a large number of objects (> 10000) and returning a small percentage of those objects to the view, an index in the data model for the field that is being queried on may be a useful place to start.

e.g.; A developer wants to query all open jobs:

function init() {
    view.jobs = DB.job.where('status = ?', 'open').orderBy('-date');
}

The above function is one that will probably work very well when there are a small number of jobs in the DB. However, to keep performance predictable as the database size scales, the developer might add an index in the data model .xml as follows:

 <model name="job" label="Job">
        <field name="date" label="Date" type="date" />
        <field name="status" label="Status" type="single-choice">
            <option key="open">Open</option>
            <option key="complete">Complete</option>
        </field>
        <display>Status: {status} Date: {date}</display>
        <index on="status" />
    </model>
2 Likes