My last small note on db4o performance will soon be outdated – fortunately. Newer releases of db4o will no longer rely on Cecil to perform reflection, thereby speeding up db4o linq queries – However, make sure you have Mono.Reflection.dll in your app! Also there are some restrictions when it comes to the compact framework and native queries (which still need Cecil), so you’d best make sure to read this official db4o announcement.
Talking about speed and performance, I just came across an issue that was also discussed in db4o forums very recently: Sort operations on large datasets.
Note: This has nothing to do with linq or linq to db4o, it’s just the same for SODA queries.
Let’s take a very common example: Find some most recent items, for example most recent blog/forum posts or some other ‘top list’ on a very large amount of entries N:
var mostRecentPosts = (from Posts o in ObjectContainer orderby o.Created descending select o).Take(100).ToList();
This query will be really really slow on a large amount of objects. Why? Essentially, the BTREE operation is very fast as it should be, but unfortunately db4o will invoke its SODA system on each of the objects, even if they are already outruled by the BTREE operation.
This is somewhat sad, because a query on a previously filtered set of items is blazing, about 100x faster:
var mostRecentPosts = (from Posts o in ObjectContainer where o.Created > yesterday orderby o.Created descending select o).Take(100).ToList();
The latter operation plays roughly in the same league as SQL Server (don’t flame me – performance comparisons and profiling is really complicated and there is a zillion of factors that influence it, I know. That’s why I say ‘roughly the same league for this query’ and I’m talking about default setups).
This is a somewhat unfortunate situation, because it produces slow queries for many typical applications – unless you have a strong where clause that cuts down N from millions to hundreds. If you’re interested in seeing this issue fixed, head over to their issue tracker and vote for the issue to be fixed! Thanks!
I’ll be posting a bit more on db4o over the next few days I hope.