为什么一个简单的 Swift 算术运算编译得这么慢? [英] Why does a simple Swift arithmetic operation compile so slow?

查看:22
本文介绍了为什么一个简单的 Swift 算术运算编译得这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了优化我的应用程序的构建时间,我在我的OTHER_SWIFT_FLAGS中添加了以下内容:

In an attempt to optimize the build time of my app I've added the following to my OTHER_SWIFT_FLAGS:

OTHER_SWIFT_FLAGS = 
-Xfrontend -warn-long-expression-type-checking=75
-Xfrontend -warn-long-function-bodies=75

我收到了一个警告,说这个特定的类型检查很慢,我不知道我是否可以在这里以某种方式帮助编译器.

I got a warnings for this specific type checking being slow, and I cannot figure out if I can help the compiler in some way here.

var delay: TimeInterval = TimeInterval(index) * 0.05

有什么建议可以加快此类基本算术运算的编译时间吗?

Any suggestions what can be done to speed up the compile time for such basic arithmetic operations up?

我使用 Swift 5 运行 Xcode 11.5

I'm running Xcode 11.5 with Swift 5

还尝试将数字显式转换为 TimeInterval,因为默认情况下所有数字都是双精度型,所以不需要这样做.

Also tried explicitly casting the number to TimeInterval, which shouldn't be needed as all numbers are Doubles by default.

推荐答案

编译器执行类型检查.如果你有一个很长的表达,它需要时间.有时当表达式太长时,你甚至会得到如下错误:

The compiler performs type checks. If you have a long expression, it takes time. Sometimes when the expression is too long, you even get an error as:

编译器无法以合理的方式对该表达式进行类型检查时间;尝试将表达式分解为不同的子表达式

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

尝试类似的东西

var delay: TimeInterval = TimeInterval(index) * TimeInterval(0.05)

这篇关于为什么一个简单的 Swift 算术运算编译得这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆