How to improve performance of the Clone operation before saving

How to improve performance of the Clone operation before saving

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


David posted on Friday, November 03, 2006

I have a BO with an EditableChildCollection which typically has about 400 items in the collection. In a typical usage scenario the user will update a couple of items in the collection and then I do a save (which is actually on an auto-save timer).

Currently the save operation takes 3 to 4 seconds which is too long. 95% of this time is taken up by the Clone operation just prior to doing the save. Is there some way to get around this?

I have experimented doing the save without the clone and it is very fast, but I understand I will get caught out here if something fails during the save operation - leaving me with an invalid object.

 

ajj3085 replied on Friday, November 03, 2006

Do the children really have to be children?   That is, can they only be changed when the parent is changed, and not independantly?

Having this many children that can ONLY be modified when the parent is modified is unusual.  Typically, there is a relation between the parent a children, but the children can be made root objects themselves. 

Can you tell us a bit about the use case and the design you have to fulfill that use case?

David replied on Sunday, November 05, 2006

I have chosen an editable child collection because I want to edit each record in a grid. I could of course make it an editable root collection but that wouldn't solve the problem as it is the collection that is taking a long time to clone.

 

Here's the situation. The user needs to record the registration of athletes for a race. 95% of the athletes have raced before and are on file. Currently they print the list of names from their database on a registration sheet, and simply write the race number next to each person's name as they present for registration. New athletes are added to the end of the list.

 

So I have provided them with an updatable grid as it best matches their current system. I tried to think of alternative approaches, but a grid is intuitive to use and minimises the use of the keyboard. Both of these are important factors as inexperienced users will be using the application, and the time taken (by the user) for each update is critical.

 

The only way I can see to avoid the large collection is to fall back to master-detail style approach, and use a read only collection with a single editable object. This would solve the 'clone' problem, but it is a compromise from a usability point of view.

 

I should point out that it is not the save operation that is slow - it is the clone that takes the time. Every time I save the parent only a couple of records actually result in a database update. If I save the current object directly performance is great.

 

I was thinking that maybe I could create a second collection that just contained the modified items, and then clone and save that. I would then have to move the saved items back into the original collection after the save. How does that sound?

 

ajj3085 replied on Monday, November 06, 2006

To answer your original question, I don't think there's anything you can do to speed the clone operation.  Any such modification that would make it run faster wouldn't return a true clone.

If you use an EditableRootList, I don't think that the entire collection is 'saved' at once.  I believe that children as saved immediately, which means only one object is cloned and saved at a time. 



Andy

Copyright (c) Marimer LLC