aspose file tools*
The moose likes Performance and the fly likes Private methods unused are a matter of performance? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Private methods unused are a matter of performance?" Watch "Private methods unused are a matter of performance?" New topic
Author

Private methods unused are a matter of performance?

Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Hello, in a project I'm working on are private methods that are used through reflection by Hibernate and another propietary framework.

The source code has been inspected by Findbugs. Since those private methods are not called from
any other project's class, Findbugs has reported performance issues because those are not used, but they are used...

The error reported by Findbugs is:

Performance - Private method is never called
Plugin: findbugs Key: UPM_UNCALLED_PRIVATE_METHOD
This private method is never called. Although it is possible that the method will be invoked through reflection, it is more likely that the method is never used, and should be removed.


Why could be considered a performance problem?.

However, I'm trying to convince developers to change those methods to protected or package-protected, but they don't
want because those methods don't have to be called by any class within the project but by Hibernate and the propietary framework. Any ideas?


http://serfj.sourceforge.net - Simplest Ever REST Framework for Java
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

"Firebug" is a Javascript debugger for Firefox; I think you're talking about "Findbugs", which is a static source code analyzer, yes?

Anyway, if you had a thousand classes, and each of them had ten unused private methods, and the compiled code for each of those took up 100 bytes, then your JAR file would be one megabyte larger than it needed to be. A larger-then-needed JAR file will take longer to load than a smaller one; that's honestly the only measurable performance problem that I can imagine due to unused private methods.

Findbugs has many, many, MANY checks that it can do; please don't fall into the common trap of believing that each of those checks is actually useful for your team. Use the checks that make sense; ignore (turn off) the ones that don't. This one definitely doesn't.


[Jess in Action][AskingGoodQuestions]
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Ernest Friedman-Hill wrote:"Firebug" is a Javascript debugger for Firefox; I think you're talking about "Findbugs", which is a static source code analyzer, yes?


Yes, it was a lapso



Anyway, if you had a thousand classes, and each of them had ten unused private methods, and the compiled code for each of those took up 100 bytes, then your JAR file would be one megabyte larger than it needed to be. A larger-then-needed JAR file will take longer to load than a smaller one; that's honestly the only measurable performance problem that I can imagine due to unused private methods.

Findbugs has many, many, MANY checks that it can do; please don't fall into the common trap of believing that each of those checks is actually useful for your team. Use the checks that make sense; ignore (turn off) the ones that don't. This one definitely doesn't.


Well, I think it's very important to detect unused private methods, because in large projects it's a matter of maintainance. I have downgraded the priority of this rule from critic to major, but that rule is not useless.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

To the best of my knowledge, the Java compiler's optimizer is thorough enough that when it detects an obviously unusable resource, it will simply refuse to waste time or space compiling that resource. YMMV, however, depending on whether you compiled with debugging enabled.

A variation on this is automatic inlining. C++ was developed with an "inline" qualifier that notified the compiler that the qualified code was small enough and lightweight enough that the compiler could avoid setting up the call/return overhead and simply expand the code in-place at the point where it was "called". Java doesn't have this feature and it's my understanding that one reason why is that when the compiler detects that a method meets certain specified criteria, it will be inlined automatically. Short private methods are good candidates, for example.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Eduardo Yañez Parareda wrote:I have downgraded the priority of this rule from critic to major, but that rule is not useless.

In general, it isn't useless. If it gives you a large number of false positives, it is. Who is going to keep going through the warnings to see when a real one shows up?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Jeanne Boyarsky wrote:
In general, it isn't useless. If it gives you a large number of false positives, it is. Who is going to keep going through the warnings to see when a real one shows up?


Yes, I know it could be useless, but as you said sometimes it isn't, that's why I lowered the priority. Who is going to look it?, developers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Private methods unused are a matter of performance?