Nice little feature in AL when thinking about performance is SetLoadFields Function. It sets the fields to be initially loaded when the record is retrieved from database, meaning that for example if you do define Item.SetLoadFields(Description) only Description Field will be retrieved from the database along with the fields that always selected for loading: Primary key, SystemId, and data audit fields SystemCreatedAt, SystemCreatedBy, SystemModifiedAt, SystemModifiedBy, fields that are filtered upon, and all other fields will be unloaded.
Also, a good method to use is SetBaseLoadFields(), that will omit loading of fields that are coming from table extensions so, you have only fields that are from base table to work with, not worrying about how many extensions are installed and lowering performance of your own code for which extensions are usually irrelevant.
And now comes the “Be careful” part if you in want to use “Description 2” for example in your later process you will receive nice little warning/error (depending how you setup your CodeCop alert) that using a “Description 2” field will cause a JIT load.
And this is one thing you should be careful about since every unloaded field will cause JIT load (Just-in-time loading). The platform, in such a case, does an implicit Get on the record and loads the missing field. Get calls can often be served by the server's data cache or can be resolved as a clustered index operation on the database, nevertheless they are one more call that you should avoid in order to have the best performance.
JIT load may also fail for multiple reasons, like:
• The record has been modified between the original load and the subsequent JIT load.
• The record has been deleted between the original load and the subsequent JIT load.
• The record has been renamed between the original load and the subsequent JIT load.
One more thing you should care about is passing a partially loaded record as a function parameter, since CodeCop does not look for the JIT load outside of the scope of the function, be very careful not to cause JIT load when passing Partial Record as a parameter. Since this will cause a JIT load and lower the performance.
Example:
Comments
Post a Comment