首页 > 解决方案 > 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).

标签: iosswiftxcode

解决方案


代码格式化一般来说,无论是空格、注释还是其他装饰器都不会影响代码编译后的性能。

随着越来越多的“非代码”字符被添加,项目的编译/构建时间可能会受到负面影响,因为预解析器必须将它们剥离。


推荐阅读