Swift编译器是否足够聪明,能够优化掉多个重复的方法调用以返回相同的对象?或者,我应该首先将返回值赋给一个常量,然后使用它?Swift Performance
例如:
的Table View Programming Guide for iOS说,添加的子视图的
UITableViewCell
的contentView
时,避免使它们是透明的。 “透明子视图会增加合成成本,从而影响滚动性能。”所以,我经常做到以下几点:
class EmployeeCell: UITableViewCell { var nameLabel: UILabel var titleLabel: UILabel // ... init(style: UITableViewCellStyle, reuseIdentifier: String) { nameLabel = UILabel(frame: CGRectZero) nameLabel.backgroundColor = UIColor.whiteColor() titleLabel = UILabel(frame: CGRectZero) titleLabel.backgroundColor = UIColor.whiteColor() // ... super.init(style: style, reuseIdentifier: reuseIdentifier) } }
它会更好,然而,第一个(内
init
)做let whiteColor = UIColor.whiteColor()
,然后用whiteColor
替换每次调用UIColor.whiteColor()
?或者,也许在这个例子中,我定义一个函数(内
init
)创建一个UILabel
与CGRectZero
一个frame
和UIColor.whiteColor()
一个backgroundColor
,只是调用初始化每个标签属性。如果我那样做,will Swift know to optimize (perhaps inline) that function?
0
A
回答
0
使用swiftc -help有很多的选项,使用-emit-XXXX看到细节
相关问题
- 1. Neos Performance
- 2. Select performance
- 3. Reflection.Emit Performance
- 4. silverlight xaml staticresouce performance
- 5. QTMovie addImage performance
- 6. stringtokenizer java - performance
- 7. Rails serverside handlebars performance
- 8. qt performance - OpenGL
- 9. Mongo $ in operator performance
- 10. mod_wsgi-express slow performance
- 11. Firebug&Performance Question?
- 12. Laravel 4 Facades Performance
- 13. RowVersion和Performance
- 14. Cassandra multiget performance
- 15. MYSQL GROUP BY PERFORMANCE
- 16. performance stringbuf vs string
- 17. android performance tunning?
- 18. Beautifulsoup4 performance raspberry pi3
- 19. live('click')and performance
- 20. Spark Slow Performance
- 21. TagSoup vs JSoup :: Performance?
- 22. .Net Profiler/Performance tuning
- 23. git vs mercurial performance
- 24. VS 2010 Performance Explorer
- 25. Performance-Billion Counter
- 26. GCC mtune performance
- 27. plone.app.theming xi:include performance
- 28. Render-call performance drain
- 29. For loop performance
- 30. Polymorphic Performance Hit
我不认为它会产生有意义的性能影响无论哪种方式,所产生的工作。不管它在这个特定情况下的行为如何,我认为依靠编译器的实现细节并不是一个好主意 – Jiaaro
@Jiaaro可能不是这样一个小例子,但是如果这个类做了非常重要的信息,它可能会更有趣(例如,如果我在100次以上的战利品中调用此方法,并且表视图可能有1000行)。请记住,swift正处于测试阶段。所以,行为可能会改变。 – Matt3o12