I have a utility class which has non static methods with no instance variables. So I am thinking of converting all the methods to static methods. I doubt there will be any memory or performance impacts. But I just wanted to confirm.
Will changing such a method to be a static have any performance impact on the program?
One final thing to add to what people have said here.
Using a
staticmethod has a slightly less overhead due to the fact that you have guaranteed compile time binding. Static method calls will create the bytecode instructioninvokestatic. ]In a typical scenario, instance methods are bound at runtime, and will create the bytecode instruction
invokevirtualwhich has higher overhead thaninvokestatic.However, this only becomes relevant in the case of likely millions of iterations, and i would caution against this driving your class design. Do what makes sense from a design perspective. Based on your description,
staticmethods are probably the way to go. In fact, this is relatively standard practice to create a utility class: