Inherited objects are stored slower than simple objects. That is happening, because parent class indexes are created and stored to the database as well.
The following example shows the influence of a simple inheritance on the insert performance:
01private void RunInheritanceTest() 02
{ 03
Configure(); 04
Init(); 05
Clean(); 06
System.Console.WriteLine("Storing " + _count + " objects of depth " + _depth); 07
Open(); 08
Store(); 09
Close(); 10
11
Clean(); 12
System.Console.WriteLine("Storing " + _count + " inherited objects of depth " + _depth); 13
Open(); 14
StoreInherited(); 15
Close(); 16
}
1private void Configure() 2
{ 3
IConfiguration config = Db4oFactory.Configure(); 4
config.LockDatabaseFile(false); 5
config.WeakReferences(false); 6
config.Io(new MemoryIoAdapter()); 7
config.FlushFileBuffers(false); 8
}
1private void Init() 2
{ 3
_count = 10000; 4
_depth = 3; 5
_isClientServer = false; 6
}
01private void Store() 02
{ 03
StartTimer(); 04
for (int i = 0; i < _count; i++) 05
{ 06
Item item = new Item("load", null); 07
for (int j = 1; j < _depth; j++) 08
{ 09
item = new Item("load", item); 10
} 11
objectContainer.Set(item); 12
} 13
objectContainer.Commit(); 14
StopTimer("Store " + TotalObjects() + " objects"); 15
}
01private void StoreInherited() 02
{ 03
StartTimer(); 04
for (int i = 0; i < _count; i++) 05
{ 06
ItemDerived item = new ItemDerived("load", null); 07
for (int j = 1; j < _depth; j++) 08
{ 09
item = new ItemDerived("load", item); 10
} 11
objectContainer.Set(item); 12
} 13
objectContainer.Commit(); 14
StopTimer("Store " + TotalObjects() + " objects"); 15
}
1public class ItemDerived : Item 2
{ 3
4
public ItemDerived(String name, ItemDerived child) 5
: base(name, child) 6
{ 7
8
} 9
}
The following results were achieved for the testing configuration:
.NET:
Storing 10000 objects of depth 3
Store 30000 objects: 1237ms
Storing 10000 inherited objects of depth 3
Store 30000 objects: 1699ms