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.out.println("Storing " + _count + " objects of depth " + _depth); 07
open(); 08
store(); 09
close(); 10
11
clean(); 12
System.out.println("Storing " + _count + " inherited objects of depth " + _depth); 13
open(); 14
storeInherited(); 15
close(); 16
17
}
1private void configure(){ 2
Configuration config = Db4o.configure(); 3
config.lockDatabaseFile(false); 4
config.weakReferences(false); 5
config.io(new MemoryIoAdapter()); 6
config.flushFileBuffers(false); 7
}
1private void init(){ 2
_count = 10000; 3
_depth = 3; 4
_isClientServer = false; 5
6
}
01private void store(){ 02
startTimer(); 03
for (int i = 0; i < _count ;i++) { 04
Item item = new Item("load", null); 05
for (int j = 1; j < _depth; j++) { 06
item = new Item("load", item); 07
} 08
objectContainer.set(item); 09
} 10
objectContainer.commit(); 11
stopTimer("Store "+ totalObjects() + " objects"); 12
}
01private void storeInherited(){ 02
startTimer(); 03
for (int i = 0; i < _count ;i++) { 04
ItemDerived item = new ItemDerived("load", null); 05
for (int j = 1; j < _depth; j++) { 06
item = new ItemDerived("load", item); 07
} 08
objectContainer.set(item); 09
} 10
objectContainer.commit(); 11
stopTimer("Store "+ totalObjects() + " objects"); 12
}
1public static class ItemDerived extends Item { 2
3
public ItemDerived(String name, ItemDerived child){ 4
super(name, child); 5
} 6
}
The following results were achieved for the testing configuration:
Java:
Storing 10000 objects of depth 3
Store 30000 objects: 883ms
Storing 10000 inherited objects of depth 3
Store 30000 objects: 938ms