John Smith
John Smith

Reputation: 409

Can inheriting unwanted class members affect application's performance?

Let's say we have some super class X:

class X {
   // Method needed in most of the instances.
   public a() { }

   // Method needed in minority of instances.
   public b() { // Large method body implementation. }
}

And we have some class Y extends X where Y is being instantiated significant amount of times.

My question is whether presence of method b in all instances, despite being needed in few, considering it's large content, can negatively affect project's speed or size. Is this the situation where the method b perhaps shouldn't be member of class X since it is highly underutilized?

To be clear this situation occurred in JavaScript code.

Upvotes: 1

Views: 34

Answers (1)

Bergi
Bergi

Reputation: 664346

No, absolutely not. First, the method is not present in all the individual instances but only in the class' .prototype object. Second, the size of methods (the function objects) is not related to the code size of their body.

Upvotes: 3

Related Questions