Hello,
I have a performace problem related to the "objectsToSave"-ArrayList contained in the class XPObjectSpace.
I have a Session which is connected to an XPObjectSpace. I am creating lots of domainobjects within this Session (30000).
Each time after I have created 30 domainobjects I am calling Session.CommitTransaction() or UnitOfWork.CommitChanges().
I know that it may not be correct to do this. I think that I should call XPObjectSpace.CommitChanges() here.
The main problem is that each time the method SetPropertyValue is called on a domainobject then the method XPObjectSpace.SetModified will be called.
protected override void SetModified(Object obj, ObjectChangedEventArgs args) {
CheckIsDisposed();
if(obj != null) {
XPClassInfo objClassInfo = FindObjectXPClassInfo(obj);
if(objClassInfo != null && objClassInfo.IsPersistent) {
if(!objectsToSave.Contains(obj)) {
objectsToSave.Add(obj);
}
…
}
Because of the fact that "objectsToSave" is a ArrayList the method call objectsToSave.Contains(obj) will lead to an iteration over all domainobjects contained in this ArrayList (with lots of equals-checks). This will have a significant performance impact if you have a lot of uncommitted domainobjects in the XPObjectSpace. Wouldn't it be better to implement "objectsToSave" with a HashSet in order increase the perfomance in general.
Another minor problem:
The main problem occurs in the described scenario only because a call to Session.CommitTransaction() (or UnitOfWork.CommitChanges()) will not clear the "objectsToSave"-ArrayList in the according XPObjectSpace. This will only be done if XPObjectSpace.CommitChanges()
is called directly. Maybe the XPObjectSpace could track commits of the underlying Session and clear the "objectsToSave"-ArrayList. But this is not the very important here. I just wanted to mention it. I can solve this simply by calling XPObjectSpace.CommitChanges().
The main problem will arise if I want to create many domainobjects and want to commit them in a single database-transaction.
You can reproduce both problems with the attached sample project. Call the action "CreateTestData" and profile how must time is lost in method XPObjectSpace.SetModified().
Thanks
Frank