Saturday, February 23, 2008

Hibernate Peformance Again

So Hibernate really is adding a significant amount of overhead compared to JDBC when querying the database. As shown in my previous blog, the overhead of processing a row seems to be quite high compared to JDBC (i.e. over double).

I've done quite a bit of investigating trying to work out the root cause. Initially I thought it might be the connection pool, so I switched from using C3P0 to DBCP, but that made no noticeable difference. I also adjusted the JDBC connection to work from the connection pool and use a proper transaction for the query. This slowed the JDBC code down a bit, but there was still a big gap.

The best I can make out, having done some profiling, is that the hydrating of objects from the database is really causing a significant performance cost which is proportional to the rows retrieved. I guess this is to be expected given the complexity of the problem of mapping between a relational database and an object model.

One useful performance improvement was to mark the transaction as read-only when performing the queries. This seemed to save about .5 m/s.

No comments: