英文:
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语言编写的,那么这个自举编译器在编译时间上会更慢吗?
英文:
Go 1.5 managed to release a bootstrapped compiler written in Go.
Assuming Go is slower than C, and the earlier Go compiler is written in C, is the bootstrapped compiler going to be slower in compilation time?
答案1
得分: 7
是的,Go 1.5编译器较慢,正如发布说明中所讨论的那样:
在Go 1.5中,构建速度将慢大约两倍。将编译器和链接器从C语言自动翻译成Go语言导致生成的Go代码不符合惯用写法,性能较差。分析工具和重构有助于改进代码,但仍有许多工作要做。在Go 1.6和未来的版本中将继续进行进一步的分析和优化。更多详细信息,请参阅这些幻灯片和相关的视频。
再次强调,编译器是(最初)自动翻译的,因此在翻译后输出的代码与之前相同:你的程序之所以变慢并不是因为编译器。发布说明的其余部分和上述链接提供了更多信息。除了编译速度之外,还有其他考虑因素:作者们希望在Go中进展得比在C中更快。
我建议你升级:开源代码将开始依赖于1.5版本,如果你停留在旧版本,将会失去很多很酷的功能,比如将大部分GC工作推入后台以大幅减少GC延迟(也在上面链接的性能部分中讨论过;我在回答另一个问题时写了更多相关内容)。
就像进行任何大型升级一样,你应该进行测试,以确保像使用所有可用核心的新默认设置、调度的微调或任何库行为变更等不会对你产生负面影响。
英文:
Yes, the Go 1.5 compiler is slower, as 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.
Again, the compiler was (initially) automatically translated, so after the translation it output the same code as before: your programs aren't slower because the compiler is. The rest of the release notes and the links above shed more light. There are considerations other than compile speeds involved: the authors intend to move faster in Go than they could in C.
I'd recommend upgrading: open-source code will come to depend on 1.5, and if you stay behind you lose a lot of cool stuff, like big reductions in GC latency from pushing most of that work into the background (also discussed in the Performance section linked above; I wrote a bit more about it responding to another question).
You should, as with any big upgrade, test to make sure that stuff like the new default of using all available cores, tweaks to scheduling, or any of the little library behavior changes don't bite you.
答案2
得分: 0
好的,以下是翻译好的内容:
PyPy是用Python编写的,它被认为比用C编写的CPython更快(有时候)。
就Go语言而言,这种语言使编写更高效的代码更容易,因此它不应该比旧版本的C语言慢。编写者在这方面非常小心。与其说是更快,不如说更容易维护和扩展。
C语言之所以快,是因为它与CPU接近,但语言的速度主要取决于生成更“高级”功能的算法(简单易用但与CPU功能相比较先进)。
一个经典的例子是内存管理。C语言的malloc/free在释放内存时会重新组织空闲内存,因此本质上较慢。垃圾回收器听起来要慢得多,因为它需要进行一些工作,但你的程序可以释放内存并以全速继续运行。
英文:
Well, PyPy is written in Python and it is known to be faster (sometimes) than CPython written in C.
In the case of Go, the language makes it easier to write more efficient code, so it should not be slower than the older C version. The writers were careful to make sure of this. Rather than faster it is easier to maintain and extend.
C is fast because it is close to the CPU, but the speed of a language is mostly more about the algorithms to produce the more 'advanced' feature (simple to use but advanced compared to CPU features).
A classic example is memory management. The C malloc/free is inherently slow as it reorganises free memory whenever you release it. A garbage collector sounds a lot slower because of the work it needs to do, but your program can release memory and continue on at full speed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论