Very small optimization

I have many functions bound to render stepped and I often do something like this:

runSvc:BindToRenderStep('run', 0, function()
	something.CFrame = start:Lerp(fin, tick() - last > db and 0 or math.sin((tick() - last) / db * math.pi));

Is this worse, better, or identical to the following since it has less boolean logic but a conditional?

runSvc:BindToRenderStep('run', 0, function()
	if tick() - last > db then
		something.CFrame = start;
		something.CFrame = start:Lerp(fin, math.sin((tick() - last) / db * math.pi));

Since I use the former option a ton, I started wondering about whether it would make a difference given that it runs every frame.

1 Like

By the looks of this, it should make very little difference. Both do basically the same thing. The second one may be very slightly better than the first because it doesn’t run CFrame:Lerp() every time.

I say don’t stress it, these micro-optimizations don’t impact performance very much even when running every frame. It’s almost always something else causing the lag or poor performance.


I’ll just keep using the first one then. Thank you!