I do like to write really readable code in Java. For that I use the builder pattern and have a lot of static methods. But at some point I do call or chain a lot of methods, so I came up with this question: Does it have any performance issues calling a lot of methods?
What the method does has a far greater effect than the method call itself. This is a pre-mature optimization that you would be advised to avoid.
You have no idea how runtime optimizations built into the JVM itself will affect performance. They will be much smarter than your attempts.
Write your app, profile it, and see if there are any obvious improvements you can make. Repeat until performance is acceptable.
Readability is almost always the way to go. There is impact on performance for function calls but non readable code will probably suffer from other implementation issues that will have higher performance hit.
Use the keyword final where appropriate so that you suggest inlineing for these functions.
A situation where you don't want to use a lot of function calls are tight loops. Something that happens hundred of thousands of times. And usually these places can be optimized at the end if optimizing the software is needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With