After reading this article you will know:
- Best practices for improving your application performance
In this article we will show you some of the most common parts of your application which could use some improvement. Improving performance is more critical than ever. Our always-on, hyper connected end users demand blazing fast experiences. The Betty Blocks platform facilitates certain performance improvements out of the box, others have to be implemented by the developer.
Try to avoid the use of expression properties as much as possible. Every time a dependent property is changed, the expression will be recalculated in the background resulting in a longer waiting time for background actions. In some cases it is better to calculate a value by using a before or after save action instead of using an expression.
Expressions on import models
Try to avoid the use of expression properties on models where records are imported via large CSV or XLSX files. For each record that is imported the expressions for that record will be recalculated, resulting in a very large waiting time.
Expressions depending on other model properties
When you've got an expression property that uses a property from another model, every time one of the properties of the other model is changed, your expression will be triggered as well. For example, when you have invoice.price, invoice.vat_price and invoice.total_price that are all sums of the invoice_items, every time you add or change an invoice item for that invoice it will trigger the expressions on the invoice as well. So when you've got 100 invoice items on one invoice, about 300 expression properties will be triggered.
Try to avoid this by calculating the prices of the invoice using an action that is called after adding all of the invoice items. The calculation will be done only once instead of 100 times which is far more efficient.
Skip triggered actions if they are not of use in that case
Every time you do a create or update event in an action, you can specify which triggered actions should be skipped. Try to skip as many as possible if they are not of use in that specific create or update event.
Make sure you never update var:record in an after_save action
This is very inefficient and even triggers the same after_save action again, potentially resulting in an infinite loop. Instead, try to use before_save action with an assign event. This will trigger no extra database save actions and model actions.
Use caching on your page
This may be the easiest setting to apply. While the Betty Blocks platform is only becoming faster, Liquid is not. When collecting a lot of data from your database on your page, loading times on your page will increase. By enabling caching, the first visit of the page will cache a lot of data in your browser. This results in shorter loading times when visiting this page at a later time.
Use indexing on search properties
Go through all your models and make sure the checkbox “Index Values” is checked on the right properties. You should also check your application log for adding indexes. Your application will log warn messages indicating a search is done on an unindexed property and you should try to add an index. Indices are increasing search performance on that specific property. Unless updating or creating records is the performance bottleneck, don’t hesitate to add up to 20 indexes per model.
Minimize the use of multi lines
This mostly applies to datamodels with many properties. Multi Line text properties tend to slow down database queries.
Below, you can find a checklist with the first things to check when improving your application performance.
- Make sure you have unchecked “Debug action and events” on all actions and endpoints. Debugging causes the platform to log the value and state of all steps and variables from an action. This should only be used during development.
- Make sure you’re not unnecessary logging any messages in actions events.
- Run through your Global Variables. A Global Variable will be loaded at the execution of every action and every page, think twice before creating global variables.
- Try to minimize the number of columns in a grid, especially when properties from other models are shown as well. Each other model will result in another database join.
- On slow models, minimize the use of Multi Line text properties, they tend to slow down database queries.