Reputation: 5190
I wanted to ask how you guys in general use batch-size
within the mappings. Do you in general set a certain number on any mapped collection? Of course, I do know about the other fetching strategies like join fetch
, but sometimes I have to filter during post processing, which might trigger lot's of lazy loading. I figured out if I set the batch-size e.g. to 100, I have much better performance in such cases.
Do you set this property in general on any mapped collection? If not, why not? Could there be any disadvantage?
Upvotes: 4
Views: 4462
Reputation: 22424
Setting batch-size
on collections or on parent entities are going to pretty much do the same thing.
What batch-size
is really doing is taking a SELECT N+1
issue and turning that into a SELECT N/batch-size + 1
condition.
There is an disadvantage and that is you need to balance the difference between setting the right number. If you make batch-size too large, you will load too much data, if you make it too small, you will still have too many queries. How you balance this is open for debate and without setting up testing is impossible to measure.
I consider this as a micro optimisation, important as it can really reduce the select/n+1 problem. However it really isn't as important as selecting the correct fetching strategy for each scenario independently, this makes for a better strategy overall.
I also think of this as a production issue and should be tested against real users against real data.
As a side note I always set my batch-size
to be equal to my paging size, don't ask me why it just feels right!
Upvotes: 4