I have a function, lets say that it does some trivial calculation. The Controller which has this function is around 5000 lines long (Not written by me).
Now, when I call a function which has trivial calculation. Does the server has to create an Object of this really large file and then run my function?
Does every request create new Object of my Controller or once it’s created it stays there for given session.
PS : I am thinking of breaking down this code, but just wanted to know whether it will give me an advantage in performance.
Refactoringis an important aspect of continuously trying to make your code better. You should not look only atperformance enhancementas an incentive,code maintainabilityis also an important factor. A controller function having 5k lines is definitely a candidate for refactoring.To answer your original question – whether a controller object is re-instantiated on every request depends on how the framework has been designed, more often than not core framework objects get instantiated once and is referred to as and when needed.