为什么 PyPy 翻译这么慢?
将 pypy 实现转换为 c 文件并在具有 2G mem 和 Intel Core2 2GHz CPU 的现代笔记本电脑上构建 pypy-c 需要几个小时。
我知道这是一个 CPU 密集型任务,但是有必要这么慢吗?有没有机会或者空间来减少计算量,重新安排计算顺序,把时间缩短到几十分钟?
It takes hours to translate pypy implementation to c files and build the pypy-c on a modern notebook, with 2G mem and an Intel Core2 2GHz CPU.
I know it's a cpu-intensive task, but does it have to be so slow? Is there any chance or room to reduce the computation, rearrange the computing order and cut the time to tens of minutes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“CPU 密集型任务”?被提名为本月轻描淡写的作品。我自己不太了解翻译过程的细节,但即使我可以告诉你,它的每一个分析和优化过程都会对大量代码进行大量非常复杂的工作。
所以,是的,这是一项非常艰巨的任务。难怪你那微不足道的CPU会丢掉。作为参考,PyPy 人员在 2010 年 11 月对翻译流程进行基准测试。尽管他们也有 12 GB RAM,但仍然花费了大约 76 分钟 - 这导致了下一个问题:该过程需要大量 RAM(当时 64 位 Ubuntu 上需要 2.3 GB) ,不知道这些数字如何转化为您的情况)。我很确定你最终会超出你的物理内存 - 输入过多的交换和相关的性能影响。
再加上您可能有其他几个程序正在运行,窃取 CPU 时间和 RAM,我认为这很好地解释了您的经历。翻译 PyPy 是为更强大的计算机保留的。如果有什么东西可以从根本上改善这个时代,像我们这样的外人不太可能找到它。我会把这些担忧留给开发人员。
"A CPU-intensive task"? Nominated for the understatement of the month. I don't quite understand the details of the translation process myself, but even I can tell you that each of its several analysis and optimization passes does a whole lot of very complex work to a whole lot of code.
gcc -O2
or similar, which of course has a lot of parsing and checking to do and will itself have many many analysis and optimization passes to do.So yeah, it's a pretty freaking HUGE task. No wonder your puny CPU it lost. For reference, the PyPy guys used a Intel Xeon W3580 (3.33 GHz) when benchmarking the translation process in November 2010. It still took them about 76 minutes, even though they also had 12 GB of RAM - which leads to the next issue: A lot of RAM is needed in the process (2.3 GB on 64 bit Ubuntu back then, don't know how the numbers translate to your situation). I'm pretty sure you end up exceeding your physical RAM - enter excessive swapping and associated kick to performance's groin.
That, combined with the fact that you propably had several other programs running stealing CPU time and RAM, explains your experience pretty well in my opinion. Translating PyPy is reserved for more powerful computers. If there's something that can fundamentally improve these times, outsiders like us are unlikely to find it. I'd leave these worrys to the developers.