by achiary » Thu Apr 14, 2016 6:19 am
Regarding your concerns about performance and based on our experience I would recommend the following :
1) Be very cautious to use Servoy Calculations : they are very powerfull in terms of development but may take you to a poor performance at runtime; so there has to be very good reasons to use it.
2) When you need some data to be calculated you shoud analyse when it REALLY should change its value and try to change it ONLY in that situation.
I would classify this cases as follows (in order of preference to minimize overhead) :
- Data that changes in specific transactions due to business rules : for example the "due amount of an invoice" , that changes every time a payment is done against that invoice, so let´s say 1, 2 or a very small number of times in its life.
- Data that may need to be calculated when the row is inserted or updated , and this is done in the onRecordInsert and/or onRecordUpdate events methods because there may be several transactions that can fire it and it is wise and covenient to write this logic in only one place. There is a lot of data of this kind and we use it a lot to prepare information that will be queried later. This will happen several times but always fired by a change produced by a business transaction. Depending on what you are dealing with you can estimate how many times per minute, day, week, month or year it can happen.
- Data that must be calculated every time a row is accessed in order to be showed but it is not needed to update the database : in this case you may use a Servoy NOT Stored calculation that will be fired EVERY TIME the row is accessed either on a form or programatically, and the calculated value will behave like another column of the row. For example : the user is a stockholder who queries his shares and the application shows him his CURRENT money based on the CURRENT value of the stock. Another example : the number of days an invoice has been unpaid.
Disadvantage : it is calculated many times.
- Data that must be calculated every time a row is accessed in order to be showed and also it is needed to update the database with the calculated value : in this case you may use a Servoy Stored calculation that will be fired EVERY TIME the row is accessed either on a form or programatically, and the calculated value will behave like another column of the row because it actually is a column of the row. It is not easy to find examples that justify this case but people may use it because makes developmenet easier.
Disadvantages : it is calculated many times and each time an UPDATE sql sentence is executed over the database, even when the recalculated value is equal to the stored in the database.
Hope this helps you to evaluate what programming resource to use depending on which are your business rules.