Alex Rivera | Logout

Performance of Set and Get using Reflection

Asked 2012-10-21T08:05:43.647
10

Does setting and getting an object attribute using reflection (java.lang.reflect.Field get and set functions) rather than calling the set and get of the object itself, result in any significant performance differences?

Edit
Report

1 Answer

0

Yes it does make a significant performance difference, and there are lots on benchmarking results on the web to support this.

For example: http://www.cowtowncoder.com/blog/archives/2007/02/entry_32.html - which seems to be saying that a reflective call to a get or set method is ~50 times slower than accessing / updating the field directly. (And getting / setting using Field methods is slower still.)

Now these results are rather old, and (apparently) the performance of reflection has been improved in recent HotSpot JVMs. Even so, a rough rule of thumb is "an order of magnitude or more slower".

answered 2012-10-21T08:28:25.623

Your Answer