I am assigned to a job of optimizing performance of an Application.
Often it is needed to pass 16-25 parameters to the constructor, and setting them there. I want to create a class & object for this and set these values to the object and then pass. It will be good to read. But will it do any good to my task (i.e performance optimization)?
When a parameter is pass-by-reference, the caller and the callee operate on the same object. It means that when a variable is pass-by-reference, the unique identifier of the object is sent to the method. Any changes to the parameter's instance members will result in that change being made to the original value.
Java always passes parameter variables by value. Object variables in Java always point to the real object in the memory heap. A mutable object's value can be changed when it is passed to a method. An immutable object's value cannot be changed, even if it is passed a new value.
We can pass the data to the methods in form of arguments and an object is an instance of a class that is created dynamically. The basic data types can be passed as arguments to the C# methods in the same way the object can also be passed as an argument to a method.
In Java, we can pass a reference to an object (also called a "handle")as a parameter.
It might improve the performance slightly, but the main benefit would be increasing the readability of your code. A constructor with 16-25 parameters is not readable, and very hard to use.
Of course, you should only introduce new classes that make sense (i.e. the parameters are related to each other). There's no point is shoving 15-26 unrelated parameters to one class just for the sake of passing them to a constructor.
Performance differences deriving from this, if any, are very unlikely to be noticeable.
If your task is to solve performance problems, then your first job is to locate where the problems are. You do that by profiling the application. Have you done that and has it demonstrated that the problem is in the parameter passing ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With