mhgrove / Empire

JPA implementation for RDF

Home Page:http://groups.google.com/group/empire-rdf/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empire can load the same entity multiple times within a single transaction (performance issue)

jblaufuss opened this issue · comments

Our application's domain model is essentially a tree. We did not explicitly model previousSibling/nextSibling relationships in our entities, so to navigate from one child to the next, we navigate up to the parent then down to the sibling at the next index (the parent/child relationships are annotated to be lazy-loaded). However, this has been much slower than we anticipated. We are observing that some entities (for instance the root of the tree) are being loaded several times in a single transaction as we traverse our tree.

I did some debugging, and it appears this is caused by Empire's lazy-load javassist proxies. It appears that separate proxies are created for every reference to particular entity, and these proxies have no awareness of each other or of any shared state. The result of this is that if you have many references to the same entity in different places, that entity can be loaded many times (rather than just once) because the proxies repeat the work because they are unaware of the other loads. So, in our case, we were loading each parent from the database once for each of its children, resulting in many unnecessary loads which severely degraded our application's performance.

I believe other ORM tools, such as Hibernate, solve this issue by having a Session/EntityManager-scoped cache, which is checked before the ORM makes a database call. If the entity is already in the cache, then the relatively-expensive database call to load it can be skipped.

We found this issue in the develop branch (we pulled it in sometimes in early 2016).

My apologies if I've gotten any of the details wrong, I looked into this issue weeks ago and I'm writing this from memory.

I was indenting to try to add a session-scoped cache to Empire and contribute it back, but my team is moving away from Empire, so I don't think I'll get to it.

What is your team switching to?