General performance understanding question
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.)
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.
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!
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