Performance optimization: X++ coding

There are several coding tips to improve your Axapta system’s performance:
1. Use local caching
Take a value that is constantly calculated inside a loop out of that loop, and place it in a variable that is then used inside the loop. Using local caching can reduce the calls between objects and different layers. 
2. Use Aggregate function
Use sum, avg, minof, maxof and count where applicable. Because this can utilize the database’s built-in function instead of calculating and analyse data in Axapta.
3. Cache display method data
Put your display method under tables, use formDataSource.cacheAddMethod to cache the data in client.
4. Use field list
Field list can implicitly use firstonly and reduce data amount to transfer from database.
e.g. 
return (select PurchTable where
  purchTable.PurchId == ‘PA00005’).PurchName;

5. Keep the number of method calls between different layers as less as possible
Store the value in a local value or use container.
6. Use index hint carefully
If the backend database is SQL 2000 above, do not put index hint in SQL statement, just keep in mind that database optimizer is smart enough.
7. Use joins instead of multiple nested while selects
Smart joins can improve performance dramatically.
In my personal experience, it can reduce up to two third of the execution time. 
8 .  Use recordset-based operator
Recordset-based operator such as Update_RecordSet, Insert_RecordSet, and Delete_From can result in less amount database calls.
9.  Use select statement instead of Query if applicable
General speaking, select statement will have a better performance in most situations. 

Advertisements
This entry was posted in Axapta Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s