I was reading the latest feeds from Phil Richardson's blog where he mentioned a post regarding some tests that Aaron Elder of Invoke Systems had conducted using some of the more esoteric web service properties that he used to speed up data retrieval using the CRM web services.

I have been working on a bulk delete utility for CRM, which I call CRMClean. ( Phil has one he calls CRM Nuke, btw. )

Anyway, after inserting Aaron's suggested changes into the code ( and rearranging some things I had done badly ), the performance absolutely freaking screams.  It finishes processing so fast that I actually had to go check the log file to make sure it actually produced the same results as the unmodified code.

Run 1: Before making Aaron's suggested changes:

16:33:11 Processing completed. Deleted 57 items from 2 entities
16:33:11 =========================================
16:33:11 Deleted 55 items from new_1atest.
16:32:59 Deleted 2 items from account.

Run 2: After making Aaron's suggested changes ( and cleaning things up a bit ):

13:35:05 Processing completed. Deleted 57 items from 2 entities
13:35:05 =========================================
13:35:05 Deleted 55 items from new_1atest.
13:35:05 Deleted 2 items from account.

As you can see, the first run too about 12 seconds to process and the second run, took a second or so.

After reading Aaron's article, and implementing his suggestions, I started looking at how I was interacting with the CRM web services.  As I mentioned above, I had done some things that I should not have, like reconnect to the CRM web service at the start of each delete process.  This is not very smart since each reconnection to the web service creates more overhead.

I had done it this way because I wanted a stand-alone function that would allow me to delete the contents of any CRM entity.  At the time, it made perfect sense and I had never questioned the performance. But, newly educated, I determined that the connection to CRM should probably only be created once so that you only take that initial hit and don't punish the user later.

I guess I should spend just a little more time studying the examples and code from guys like Michaeljon Miller, huh? :)

Anyway, if you are going to be working with Web services, give Aaron's article a read.