Breaking Down Code Into Smaller Segments. Healthy Computing?

In genreal, is there any difference in performance between doing code like this…

	void determineTrajectory(){   			
		aPt = Nozzle2.position; // touch position
		////print("aPt " + aPt);
		bPt = Nozzle1.position; //playerObject position in screen space
		////print("bPt " + bPt);
		
		nozzleRise = aPt.y - bPt.y; /// rise
		nozzleRun = aPt.x - bPt.x; /// run	
		bulletTrajectory = new Vector2(nozzleRun, nozzleRise);
		
		bulletRayDirection = new Vector3(bulletTrajectory.x * 100, bulletTrajectory.y * 100, 0);
		bulletRay = new Ray(aPt, bulletRayDirection);
		btnPressed = true;///alllows update to register ray.		
	}

And doing code like this…

	void determineTrajectory(){   			
		aPt = Nozzle2.position; // touch position
		////print("aPt " + aPt);
		bPt = Nozzle1.position; //playerObject position in screen space
		////print("bPt " + bPt);
		
		nozzleRise = aPt.y - bPt.y; /// rise
		nozzleRun = aPt.x - bPt.x; /// run	
		bulletTrajectory = new Vector2(nozzleRun, nozzleRise);
		castRay();
	}
	
	void castRay(){
		bulletRayDirection = new Vector3(bulletTrajectory.x * 100, bulletTrajectory.y * 100, 0);
		bulletRay = new Ray(aPt, bulletRayDirection);
		btnPressed = true;///alllows update to register ray.
	}

Obviously, this is nominal, but on a massive scale, or just in general, is it more healthy for the engine, if code is broken down. Above all else, I generally prefer the second method due to better read back ability. It makes more sense to me, if I go back to it, after a while. But, is there any difference in performance? If so, why?

Well separation of concerns eg example 2 … is great for usability and structure. But as you are strictly asking about performance obviously it has two function calls instead of just one so it costs more to process(accessing the heap) . Unrolling method calls is a very last minute optimization if you are really trying to squeeze every micro second out possible … I would say always favor structure and readability first as a golden rule.

Good presentation of a script always makes it easier to read and understand (especially if you haven’t revised it in ages) and generally doesnt affect performance. However, in your second example, you shouldn’t be calling two functions - it takes more memory than the first!:smile:

Ok!
Thanks!