objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

General performance understanding question

Open JimmyTheNerd opened this issue 8 years ago • 3 comments

First of all: thanks for your great work! :-)

I've to do some calculations, which require search/sort/order/filter/..., quiet often and I would like to find a stable, fast and readable way.

Approach 1: get items and process myself

List<MyItem> allItems = myBox.getAll(); // all items will be needed at some point
List<MyItem> activeItems = filterActive(allItems);

Approach 2: use the convenience of ObjectBox

List<MyItem> activeItems = myBox.query().equal(MyItem_.active, true).build().find();
// ...

It's a bit more complex than that and I expect about 50 reading operations per batch for 500 records in 5 tables. The batch is restarting once it's finished.

I would usually prefer the 1st approach but after seeing the benchmarks, I was hoping that ObjectBox does some magic in the background that makes using it less expensive

What is the recommended way of using ObjectBox?

Thank you!

(Yes, I read the FAQ and know that ObjectBox isn't a "zero copy" database.)

JimmyTheNerd avatar Oct 10 '18 05:10 JimmyTheNerd

For performance consideration, you should prefer native queries to do pre-selection for filtering. Loading a couple of hundred objects for filtering is usually fine.

greenrobot avatar Oct 10 '18 08:10 greenrobot

Thanks, @greenrobot !

For performance consideration, you should prefer native queries to do pre-selection for filtering.

Could you please help me to understand what you meant by native queries? I couldn't find anything in the docs, but some private methods in the source code (src/main/java/io/objectbox/query/QueryBuilder.java).

Loading a couple of hundred objects for filtering is usually fine.

Great!

JimmyTheNerd avatar Oct 11 '18 07:10 JimmyTheNerd

It means to use your "approach 2" to filter your results as much as possible, only then do the remaining filtering in Java/Kotlin code.

Closing. Please feel free to re-open if this did not answer your question. -ut

greenrobot-team avatar Oct 29 '18 12:10 greenrobot-team