Go 1.5 的自举编译器是否比用 C 编写的 Go 1.4 编译器慢?

Is Go 1.5's bootstrapped compiler slower than the Go 1.4 compiler written in C?

Go 1.5 成功发布了一个用 Go 编写的自举编译器。 假设 Go 比 C 慢,并且早期的 Go 编译器是用 C 编写的,那么自举编译器的编译时间是否会更慢?

好吧,PyPy 是用 Python 编写的,并且众所周知(有时)比用 C 编写的 CPython 更快。

就 Go 而言,该语言可以更轻松地编写更高效的代码,因此它应该不会比旧的 C 版本慢。编剧们小心翼翼地确保这一点。不是更快,而是更容易维护和扩展。

C 之所以快,是因为它接近 CPU,但是语言的速度主要更多地与算法有关,以产生更多 'advanced' 特性(使用简单但与CPU 个功能)。

一个典型的例子就是内存管理。 C malloc/free 本质上很慢,因为它会在您释放它时重新组织空闲内存。垃圾收集器由于需要完成的工作而听起来慢很多,但您的程序可以释放内存并继续全速运行。

是的,Go 1.5 编译器比较慢,因为 discussed in the release notes:

Builds in Go 1.5 will be slower by a factor of about two. The automatic translation of the compiler and linker from C to Go resulted in unidiomatic Go code that performs poorly compared to well-written Go. Analysis tools and refactoring helped to improve the code, but much remains to be done. Further profiling and optimization will continue in Go 1.6 and future releases. For more details, see these slides and associated video.

同样,编译器(最初)是自动翻译的,因此在翻译后它输出与以前相同的代码:您的程序不会因为编译器变慢而变慢。 The rest of the release notes 和上面的链接更清楚。除了编译速度之外,还有其他考虑因素:作者打算在 Go 中比在 C 中移动得更快。

我建议升级:开源代码将依赖于 1.5,如果你落后,你会失去很多很酷的东西,比如通过将大部分工作推到后台来大幅减少 GC 延迟(也在上面链接的性能部分中讨论过;我写了更多关于它的内容 )。

与任何重大升级一样,您应该进行测试以确保诸如使用所有可用内核的新默认设置、调度调整或任何 library behavior changes 的小细节不会影响您。