Hi all
JPAContainer seems to have a hard time working efficiently in Vaadin 6, partly because the container API doesn’t make it easy for JPAContainer to predict which ranges of data will be required and when. When I look at the call patterns I see that there’s often a “for each entity ID, for each property, do …” sort of pattern of calls. This can result in truly horrible performance - at least n+1 queries, but worse than that if there’s lazy loading going on too.
Is there any chance the container API for Vaadin 7 will be able to focus on working with ranges of entries more? Instead of:
- Count number of entities matching filter
- Get IDs for current view range a … b as List (primary key types)
- for each ID in range:
– for each property
— ask container for entity.property
This lands up with the container doing nEntities * nProps queries, which is
horrible
. The CachingLocalEntityProvider helps a little, but it shouldn’t be
necessary
if the API gave the container the right information to start with.
It’d be really helpful if the table and container model could instead try to:
- Count number of entities matching filter or allow open-ended pagination
- Get entities for current view range a … b as a List
- Request a Map<Entity, List> or Map<Entity,Map<String,Property>> from the container for every entity in List
At least three optimisations now become possible. First, the container knows that the display component will want to use the data in the entities in range a…b, and isn’t just being asked to get the IDs. Second, it knows which properties of these entities will actually be used, so it can ensure they’re eagerly loaded even if they’d usually be lazy. Third, it can work with efficient groups of entities, not having to fetch each entity by ID as it’s requested. The JPA provider can do a SELECT … WHERE id IN (…) or a SELECT … LIMIT … OFFSET… or whatever it wants to reduce round trips and make things lots faster than SELECT id … LIMIT n OFFSET followed by `n’ SELECT … FROM … WHERE id = 1 queries as is currently required.
The current approach is near pessimal for JPA. Please consider improving the API so a Vaadin 7 JPAContainer can be lightning fast.
(You might also want to get involved in
http://java.net/projects/jpa-spec
as they’ll be discussing fetch groups and per-query/per-property lazy/eager control for JPA 2.1 soon).