In: Computer Science
What are some potential efficiency disadvantages of having very shallow inheritance trees, that is, a large set of classes, A, B, C, and so on, such that all of these classes extend a single class, Z?
Deep inheritance, which is A -> B -> C -> D. Shallow inheritance, which is A -> B, A -> C, A -> D
The real question is what is the right level of abstractions to use. This is what impacts developer efficiency which is the most important thing to consider in 99% of cases. Any assumptions you make about the efficiency of how the code runs is likely to be either a) not make much difference or b) wrong or c) out of date in a future version of the JVM.
The most important CPU performance to worry about is time complexity, but more often it is developer efficiency which will cost you the most in the long run.
The only efficiency problems for a deep inheritance tree that I can see is that super may be called many times over in a deep inheritance tree when calling the constructor for the deepest class.
The JVM supports aggressive inlining. Within reason the number of times you call super doesn't matter especially if you don't add methods which add no value.
Also, if there is a method signature that is overridden in each class, the compiler will take longer to sort out or determine which method is overridden.
While this is true, the time the compiler spends compiling the code is unlikely to be important. If you have shallow inheritance A -> B, A -> C, A -> D the only methods which call super are the ones you add. i.e. the more levels you add the less like you need to override a method at every level. The JIT can also inline all these methods so it as if there was no calls from a performance point of view.
So a bunch of classes extending one class becomes disorganized.
This is very important. It lowers the efficiency of your developers and their ability to optimise the code. i.e. it can be less performant because it is harder to optimise.