Why reflection slows down Android phone

I have read many times that reflection will slow down the phone. How true is this?

For example, in my case, I get some parameters from a web service that have the same name as the class parameters that I have in an Android application. so I just set the values โ€‹โ€‹of these parameters using java fields and reflection ... this does not seem to slow performance.

can someone explain to me the fact behind this idea regarding reflection slowing down performance?

+3
performance android reflection android-ksoap2
source share
2 answers

Take a look at this question . Basically, you get beyond the optimizations that the compiler can do, because reflection happens dynamically.

If you don't make many reflection calls (for example, it would be bad to do inside getView in a ListView), you might get off with it. It will be used there, just be careful about it.

+6
source share

How true is this?

This is slower than not using reflection. This is definitely something you want to avoid in loops or during fast UI processing (like ListView scrolling).

I get some parameters from a web service that have the same name as the class parameters that I have in an Android application. so I just set the values โ€‹โ€‹of these parameters using java fields and reflection ... this does not seem to slow performance.

He does this, although in this case he may not be noticeable.

can someone explain to me the fact behind this idea regarding reflection slowing down performance?

See the link provided by @Brian Cooley in his answer. Keep in mind that thinking about the Dalvik (Android virtual machine) can be slower than reflecting on the Java virtual machine - I'm really sure that it is not faster, anyway.

+4
source share

All Articles