【问题标题】:Rules for type check in Swift builds?Swift 构建中的类型检查规则?
【发布时间】:2019-12-07 22:40:54
【问题描述】:

我想加快构建时间,因此其中一个步骤是使用 Other Swift Flags

-Xfrontend -warn-long-function-bodies=100
-Xfrontend -warn-long-expression-type-checking=100


但我不确定类型检查是如何工作的。例如,这是一个用于创建random CGFloat 的简单函数。类型检查是否超过 200 毫秒

static func randomColorValue() -> CGFloat {
    return CGFloat(Int.random(in: 0...255))/255.0
}

但是换成这样的东西

  static func randomColorValue() -> CGFloat {
         let rnd    = Int.random(in: 0...255)
         let frnd   = CGFloat(rnd)
         let result = frnd/255.0

         return result
     }

或者像这样

static func randomColorValue() -> CGFloat {
     let rnd    : Int     = Int.random(in: 0...255)
     let frnd   : CGFloat = CGFloat(rnd)
     let result : CGFloat = frnd/255.0

     return result
 }

类型检查仍然超过 200 毫秒。


这里有什么问题?是否有任何一套规则和最佳实践来处理构建时间? 我的 Mac 有点旧(2012 年),也许这就是问题所在?


编辑:

关闭-warn-long-function-bodies后出现问题行,那就是

CGFloat(rnd)

似乎将Int 转换为FloatDoubleCGFloat 显示会减慢150 毫秒。

【问题讨论】:

  • 这能回答你的问题吗? Why is Swift compile time so slow?
  • Int.random(in: Int(0)...Int(255)frnd / CGFloat(255.50) 是否可以加快速度?
  • 0...255 这样的字面量不是问题吗?
  • 谢谢,尝试了所有方法,但没有成功。见编辑。

标签: swift build-time


【解决方案1】:

请注意,warn-long-function-bodies 不受支持 (it was added as an experimental flag)。如果你去掉它,我发现表达时间通常报告两倍快,这让人相信同时使用这两个测量会造成干扰。测量也需要时间。 warn-long-expression 是受支持的选项。

【讨论】:

  • 谢谢,这个答案有部分帮助。
猜你喜欢
  • 1970-01-01
  • 2019-05-26
  • 1970-01-01
  • 1970-01-01
  • 2020-09-18
  • 1970-01-01
  • 1970-01-01
  • 2015-05-16
  • 1970-01-01
相关资源
最近更新 更多