Slowdown with AddNew

Slowdown with AddNew

Old forum URL: forums.lhotka.net/forums/t/7799.aspx


Turntwo posted on Thursday, October 15, 2009

Ok, weird problem, at least from my point of view. 

I'm doing some conversion from an old system into a new system using CSLA.  The old data is exported in text files, so I'm reading the text files to parse the data, and loading my CSLA objects with the data. 
I'm doing this using an EditList (BusinessListBase), that starts with about 3600 object (small objects, only 4 properties), and in the end will end up with around 10K. 

The first 200 or so loops run really quick - but then it starts slowing down considerably.  Going from about 10 records per second to less than 1 per second - and it keeps getting slower.  If I had started with 0 objects, and then started adding, I could understand that it slowed down as the list grew - but the change from 3600 records to 3800 shouldn't show such a marked increase. 

There is a validation rule that checks that the key is unique in the list, so it does loop through the list for each new item.  But in stepping through the code, this method takes next to 0 time. However, AddNew() on the list is taking 4 seconds after ~1400 items.  Why would AddNew() slow down so much?  I'm using the standard AddNewCore override ( .NewItem(), add, return newItem).  Using LINQ to retrieve an existing item from the list is fast, it is only when the key doesn't exist and the AddNew() is made that it slows down. 

Any ideas?  Anyone else experience a similar problem?   

RockfordLhotka replied on Thursday, October 15, 2009

There was just a thread on something like this maybe 1-2 weeks ago. IIRC, the answer in that case was that they'd forgotten to turn off RaiseListChangedEvents.

Turntwo replied on Thursday, October 15, 2009

That was it.  I guess I was using the wrong search terms, because I couldn't find anything about it. 

Thanks - you rock. 

Jason

Copyright (c) Marimer LLC