I had a function of my form that was performing very poorly. We had started talking about performance in some other threads and I posted the following GREAT article -
http://msdn.microsoft.com/office/understanding/infopath/default.aspx?pull=/library/en-us/odc_ip2003_ta/html/officeinfopathtroubleshootperformancebestpracticeguidelines.aspAnyways, I needed to get this form to perform faster. Well this is what I found:
- Be a little more careful with the type of XPath queries you are running. For example if you are using the LAST statement it seemed that I could shave a second off by directly referencing the row via index by using selectNodes()(). My timing is not scientific :-)
- I then stopped using XDocument.View.ExecuteAction("xCollection::insert", "Item_272") to create rows programmatically and instead used appendChild. With appendChild, I have to build an XML string and the row will subsequently be added. I was little bummed out about doing that because from a maintainability standpoint I loose a little bit because if the schema were to change, I have to make sure that I go into the code and modify this XML string that is being built. If I had continued to use ExecuteAction, the row is built by InfoPath using the default template of the form.
- Finally, I was seeing some improvement but it was not all that I wanted. According to the article I reference above, one of the big performance killers is conditional formatting. So what I did was hide all of the sections while performing this logic and then make it visible again when the logic was complete. I so basically took conditional formatting out of the equation and have it only execute once at the very end. This is was when the time it took to execute the function dropped from 12 seconds to 3 seconds.