Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the method name length have any impact whatsoever on the performance?

I am a senior developer, so this appears to me a stupid question. My answer should be NO, or WHAT? NO!!!

But I was in a meeting yesterday, and I was explaining some PMD results. When we get to the "too long method name" issue, I started to explain and the customer said: well, and remember a long method name has an impact on performance, the program run slower.

I said: no, you are wrong, is only a clean code rule, and is important to get a good code, but has nothing to do with performance, the bytecode is similar with different names.

But the client, and there were some people in the meeting arguing in this, was sure about this. They had some projects in that long method names were the cause of poor performance.

The only idea I have is that some introspection or reflection thing has is related to this, but apart from this, I am sure, or I thought I was Sure, the method name length has not any performance impact.

Any idea or suggestion about this?

like image 380
ERNESTO ARROYO RON Avatar asked Nov 12 '11 18:11

ERNESTO ARROYO RON


2 Answers

Arguably it will take more space in memory and storage - so a jar file containing classes with enormous method names will be larger than one with short class names, for example.

However, any difference in performance is incredibly unlikely to be noticeable. I think it's almost certain that the projects where they were blaming long method names for poor performance were actually misdiagnosed. It's not like it would be the first time that's happened.

Of course, the best way to take the heat out of this situation is to provide evidence - if performance is important, you should have tests for performance. Run those tests with long method names, then refactor them to short method names and rerun the tests. I'd be incredibly surprised if there were a significant difference.

like image 99
Jon Skeet Avatar answered Sep 20 '22 09:09

Jon Skeet


Method names are not just relevant with reflection but also during class loading and of course in both cases a long method names means that at some level there is more for the CPU to do. However, with method name length that are even remotely practical (i.e. not thousands of characters long), I am absolutely certain that it's impossible for this to be significant compared to other things that have to be done during reflection or class loading.

like image 36
Michael Borgwardt Avatar answered Sep 18 '22 09:09

Michael Borgwardt