views:

200

answers:

3

The javadoc says:

Please note that this class is designed to provide convenience rather than high performance. For best performance consider using a custom RowMapper.

How slow is it in the real world?

+2  A: 

I've never benchmarked it, because I've never found it to be a particular bottleneck. A custom RowMapper that doesn't use reflection would be faster but I've never seen a hit worth worrying about in my apps. If you're doing an extremely high performance app then it might be worth looking at, but for most purposes I think the convenience is worth the negligible hit.

A look at the source code for the base class, AbstractBeanPropertyRowMapper, suggests that a lot of the reflection-style code gets cached after the first time the class is accessed via that mapper. I cannot imagine there being any real performance issues. Quick peek: http://www.java2s.com/Open-Source/Java-Document/J2EE/spring-framework-2.5/org/springframework/jdbc/core/AbstractBeanPropertyRowMapper.java.htm

GaryF
Looks like a good task for me for the weekend with cpu profiler.
HappyCoder
+3  A: 

Invoking methods using reflection gives you a performance hit right off the start. In this situation, you're multiplying that performance hit by the number of results coming from the database. If your data will grow and you will be querying it often, consider using the ParameterizedRowMapper instead.

In the past, I've had to back-out of using reflection-happy convenience libraries because benchmarks showed that it turned a 100ms user look up into about 3 seconds.

BranTheMan
You are right. Posted my own answer.
HappyCoder
Out of curiosity, what version of the JRE did you benchmark in?
BranTheMan
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025)Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)on mac
HappyCoder
A: 

Results of profiling mapRow method with Yourkit:

Custom row mapper:
186 ms (invocation count 224 (weird...))
ParameterizedBeanPropertyRowMapper:
1301 ms (invocation count 112)

Conclusion:

On reading one row from result set, about 11 milliseconds are saved. Which means that 1 "virtual" second is saved at reading 100 records. Multiply that on the number of users and you will get the idea. ParameterizedBeanPropertyRowMapper can be used efficiently only in small apps that run on the client's machine (desktop applications).

HappyCoder