I have a small test app that persists a few hundred instances of a simple class and then performs a simple query to load them back. I have another test app that uses straight JDBC and does the same thing (ie. stores a few hundred records and then loads them back and goes through the result set and marshalls the data into class instances.)
I noticed a significant performance difference between the two apps. After some investigation, it appears to be with the way the resultSet is used. When calling resultSet.getXXX() you can either pass a string with the column name or the index. When I use an index in the JDBC test, it executes much faster than when using a string. The Javadocs for ResultSet suggest that this will be the case, due to translation and lookup that typically needs to be performed on the column name.
When I use the string parameter, my JDBC code perfomance is almost identical to that of the Hibernate code. I did a quick search of the Hibernate code and it does appear that the string version is being used.
I realize that this may be heavily driver dependent. I am using Hibernate 3.0.5 and hsqldb (latest version). Can you confirm that this is how Hibernate uses the resultSet? If so, would it be faster to maintain this mapping in the Hibernate software rather than having the driver do it? Any possibility that this could be changed? Is there any other way to avoid this hit (short of using a different driver)?
I have read a lot of threads in this forum about performance and realize it is a touchy subject. I know my example is a trivial mirco-benchmark and means nothing when compared to a real system. However, it seems that the suggested change would benefit any system.
|