I forgot where I read this but I heard that breaking if statements into multiple lines such as:

if true then
	if true then
		if true then
			if true then
				print("Tis true!")
			end
		end
	end
end

Is better for performance than:

if true and true and true and true then
	print("Tis true!")
end

Can someone guide me on this? I would preferably like to go for the second statement as it could reduce hundreds of lines in my main server (currently 3000+ lines) script but performance and speed is very important as well.

3 comments

0

The run time is lower, but performance stays the same. Performance is determined by many factors such as event listeners and the amount of loops that are running. Giving a script fewer lines to execute is only going to decrease run time; however, in some cases, it may also affect performance.

0

So with my main server script which holds around 3000 lines, should I pile the IF statements into 1 line? Note that the script is already doing some very heavy functions and maths.

0

Personally, I advise doing what you did in example 2. Compacting a script like this 1, doesn't affect performance at all. "white" or "blank" areas of the script don't affect performance either. And 2, it makes the code harder to read and comprehend later on.