SwiftyFoxx
SwiftyFoxx

Reputation: 13

Does less space in-between lines of code in Xcode make the build/app faster, or does it not make a difference?

As I was formatting my code for a project, specifically regarding uniform spacing (OCD.. hehe). I had a curious thought, does having "too much" (or too little) spacing affect code performance in any way?

I tried searching via docs & Google but was only able to find performance "tips" that were unrelated. I assume any relevant knowledge might involve understanding lower level languages (which I have very little experience). I'll post two simple examples below:

////////// - Lots Of Spacing
func exampleFunctionOne(newText: String) {

    if newText.isEmpty {

        return

    }

    exampleLabel.text = newText

    return
}


////////// - Little Spacing
func exampleFunctionTwo(newText: String) {
    if newText.isEmpty { return }
    exampleLabel.text = newText; return
}

Keep in mind, even though these examples are small, my project is currently around 20,000 lines (if that matters).

Upvotes: 1

Views: 955

Answers (2)

Mustafa Ahmed
Mustafa Ahmed

Reputation: 422

No, it doesn't affect app performance. Spacing, comments and any other non-code or pre-compile commands are being striped out before compiling. They will not be converted into binaries so they will not have any effect on your app performance.

Although, as the number of source files increase, the build time will increase naturally. With incremental builds feature in modern compilers, the effect on build time will not be noticeable. Also, some IDEs will pre-process source files when idle - and make it incremental as you do your changes - to save build time when you need a build.

Upvotes: 1

ekscrypto
ekscrypto

Reputation: 3806

Code formatting in general, whether it is spaces, comments or other decorators do not affect the performance after the code is compiled.

The compilation/build time of your project may be affected negatively as more and more "non-code" characters are added, since the pre-parser will have to strip them out.

Upvotes: 1

Related Questions