web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to improve performance in x++(Loop, Insert)

(0) ShareShare
ReportReport
Posted on by
I am in the process of modifying a class to improve performance.
I am calling a child method for insert in a parent method that is looping, is there room for performance improvement here?
I would like to know in detail how to modify it. Thank you in advance.
 
※This is a rough image.
private void【parent method】
{
    while...
    {
    ・
    ・
        this.【child method】
    ・
    ・
    }
}
 
==============================
private void【child method】(TableB, strC)
{
    TableA.XXX = TableB.XXX;
    TableA.YYY = TableB.YYY;
    ・
    ・
    TableA.ZZZ = strC;
 
    TableA.insert();
}
==============================
I have the same question (0)
  • Suggested answer
    Judy Profile Picture
    Microsoft Employee on at
    Hi, instead of calling the child method for each iteration of the loop, you can modify the child method to accept a collection of 'TableB' objects e.g.: List<TableB> List = new List<TableB>(); then perform a batch insert operation.
    This can reduce the number of database calls and improve performance.
    Hope it can give you some hints.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    305,659 Super User 2026 Season 1 on at
    Hi,
     
    There are two options for making this concept faster. In case you insert records in a loop, the database is called every insert. There can be some latency or table locks, depending on the situation. You can consider using a RecordInsertList or the command insert_recordset for one database call and better performance. 
     
    Depending on how strC is calculated, you can use both or only the RecordInsertList.
     
    You can read more here: 
     
    In one of my blogs, I also talked about insert_recordset preventing nested loops
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,803 Super User 2026 Season 1 on at
    Hi,
     
    I suggest to use RecordInsertList
     
    e.g.
     
    RecordInsertList                        myTableList;
    MyTable                                 myTable;
    
    myTableList = new RecordInsertList(tableNum(<<YourTable>>));
    
    while(<<your condition>>) // Loops
    {
       myTable.clear();
       myTable.test = 'Test'
       myTableList.add(myTable);
    }
    
    myTableList.insertDatabase();
    Best Regards,
    Mohamed Amine MAHMOUDI

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 681 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 551 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 471

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans