关于PyPy请告诉我 [英] Please enlighten me about PyPy

查看:78
本文介绍了关于PyPy请告诉我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


我一直在阅读有关PyPy的内容,但有些事情我不会理解它。我希望我能在这个

新闻组中获得一些启示。


首先,介绍:


< ;摘录>

" PyPy项目旨在生成灵活,快速的Python

实现。指导思想是将Python语言本身的Python级别的b $ b描述转换为较低级别的语言。

< / excerpt>


所以基本的想法是PyPy是Python中Python的实现

(即:用Python编写Python的解释器),然后翻译它

到另一种语言,如C或Java?它与

CPython或Jython有何不同呢?


此外,翻译是什么?这意味着什么翻译,例如,使用

Jython将PyPy翻译成Java类?或者使用Psyco翻译

PyPy到本地执行官?


< excerpt>

谣言有它这个秘密目标比C更快,这是无意义的,不是吗?

< / excerpt>


如果它被翻译成C,为什么这应该是无稽之谈?我是
意思是,PyPy与CPython的C版本都在C中,那为什么这个

应该是胡说八道?


似乎我在翻译这个词中错过了很多细微差别

这里。


此外,这一个:


< excerpt>

我们用Python编写了一个Python解释器,没有很多引用

到底层细节。 (由于Python的本质,这已经是复杂的任务了,虽然不如写入它 - 比如说 - C.)

然后我们用这个作为语言规范并操纵它来生成我们想要的更传统的口译员。在上面的

意义上,我们正在生成具体的映射。将Python改为

低级目标平台。

< / excerpt>


所以语言规范在本段_is_ Python中的Python

实现,a.k.a。:PyPy?然后是什么操纵它

来产生更传统的解释者是什么意思?


我的意思是,从我读到的内容来看,PyPy更多的是关于翻译器

将Python代码翻译成其他东西而不是

在Python中实现Python。在那种情况下,它可能是任何其他项目,对吗?如在Python中实现X,然后

翻译成另一种语言?


感谢您的任何指示!

Hello!

I''ve been reading about PyPy, but there are some things that I don''t
understand about it. I hope I can get some enlightenment in this
newsgroup :)

First, the intro:

<excerpt>
"The PyPy project aims at producing a flexible and fast Python
implementation. The guiding idea is to translate a Python-level
description of the Python language itself to lower level languages."
</excerpt>

So the basic idea is that PyPy is an implementation of Python in Python
(i.e.: writing Python''s interpreter in Python), and then translate that
into another language such as C or Java? How is it different from
CPython or Jython then?

Also, what does "translation" here mean? Translation as in, say, "Use
Jython to translate PyPy to Java classes"? Or "Use Psyco to translate
PyPy to native exec"?

<excerpt>
"Rumors have it that the secret goal is being faster-than-C which is
nonsense, isn''t it?"
</excerpt>

Why is this supposed to be nonsense if it''s been translated to C? I
mean, C version of PyPy vs. CPython, both are in C, then why is this
supposed to be nonsense?

It seems that I''m missing a lot of nuances in the word "translation"
here.

Also, this one:

<excerpt>
We have written a Python interpreter in Python, without many references
to low-level details. (Because of the nature of Python, this is already
a complicated task, although not as much as writing it in - say - C.)
Then we use this as a "language specification" and manipulate it to
produce the more traditional interpreters that we want. In the above
sense, we are generating the concrete "mappings" of Python into
lower-level target platforms.
</excerpt>

So the "language specification" in this paragraph _is_ the Python
implementation in Python, a.k.a.: PyPy? Then what does "manipulate it
to produce the more traditional interpreters" mean?

I mean, it seems from what I read that PyPy is more about a translator
that translates Python code into something else rather than
implementing Python in Python. In that case, it could have been any
other project, right? As in implementing X in Python, and then
translate to another language?

Thanks for any pointers!

推荐答案

嗯...我知道这很复杂,而且所有这些问题都会让你的b
爆炸。

我会告诉你我对Pypy的理解,同时,我会

离开大门进行进一步的解释或更正。


如你所知,python是一种动态语言。

这意味着程序员在声明变量时不提供

类型的信息,比如静态类型

语言。

它的代码不会通过编译器转换为机器代码,

就像在C中一样。

相反,它被解释了。通过interprter,它在运行时发现每个

变量类型。

这种解释使得像python这样的脚本语言比传统的慢得多

静态语言。


最近,Python通过Psyco获得了速度提升,这类似于即时编译器的概念验证。这是一个cpython扩展

它可以通过分析运行时信息和

动态生成机器代码来提高python的速度。

然而,psyco只能分析python代码,如你所知,python

依赖于c中编码的许多扩展,以提高性能。

因此它的作者决定拥有一个用
python编写的python实现为实现类似psyco的

技术奠定了更好的基础。


这个实现需要一个最小的核心,写在一个名为rpython的python的受限制的b $ b子集中。这个子集避免了python的许多最优秀的动态方面,通过使用顶级类型推理技术的工具,可以更容易地通过一个工具自动将它转换为C。 br />
这个翻译版本的rpython解释器(它已经自动翻译为c),是Pypy的基础。


除此之外,新的Psyco和即时技术将实现最佳性能。


然而,我仍然怀疑我真的理解它...

我还不确定是否会使用类型推理技术来提高在bypy上运行的程序的性能,或者如果这些

技术仅用于获取rpython口译员

翻译成c。


据我所知,pypy目前比

cpython慢​​10/20倍,尽管仍有许多优化要做。

我不确定,但我认为它的开发人员依靠

类似psyco的技术来实现他们寻找的大速度提升。


Luis

Hmmm... I know it''s complicated, and all these questions can make your
head explode.
I''ll tell you what I understand about Pypy and, at the same time, I''ll
leave the door open for further explanations or corrections.

As you know, python is a dynamic language.
It means, amongst other things, that the programmer doesn''t provide
type information when declaring variables, like in statically typed
languages.
Its code doesn''t get translated to machine code through a compiler,
like in C.
Instead, it is "interpreted" by the interprter, which finds out each
variable type at run-time.
This interpretation makes scripting languages like python much slower
than traditional static languages.

Recently, Python got a speed boost via Psyco, which is something like a
proof of concept for a just-in-time compiler. It is a cpython extension
and it can improve python''s speed by analyzing run-time information and
generating machine code on the fly.
However, psyco can only analize python code and as you know, python
relies on many extensions coded in c, for performance.
So its author decided that having a python implementation written in
python would laid a much better basis for implementing psyco-like
techniques.

This implementation requires a minimal core, writen in a restricted
subset of python called "rpython". This subset avoids many of the most
dynamic aspects of python, making it easier to authomatically translate
it to C through a tool that uses top-notch type inference techniques.
This translated version of the rpython interpreter (which got already
auto-translated to c), is the basis of Pypy.

On top of it, New Psyco-like and just-in-time techniques will be
implemented for achieving maximum performance.

However, I still doubt that I really understood it...
I''m still not sure if the type inference techniques will be used to
improve the performance of programs running on pypy, or if these
techniques were only intended for getting the rpython interpreter
translated to c.

As far as I know, pypy is currently about 10/20 times slower than
cpython, although many optimizations remain to be done.
And I ''m not sure, but I think that its developers rely on the
psyco-like techniques to achieve the big speed boost their looking for.

Luis


你好Luis!


感谢您的回复:)下面还有一些问题......
Hi Luis!

Thanks for your reply :) Some further questions below...
因此它的作者决定用python中编写的python实现为实现类似psyco的技术奠定了更好的基础。


好​​的,到目前为止,我明白了......我想。因此,它正在一个名为RPython的Python子集中实现Python

解释器,使其更易于使用类似psyco技术进行翻译。但与CPython相比,这是多么优越?
?是因为Psyco是一个特殊化工具,它可以为不同的数据集生成不同的代码吗?所以

的假设是解释器处理一组非常具体的

数据,Psyco将能够用来生成非常高效的数据。
机器代码?


我仍​​然不知道这怎么可能优于手工编码的C版

虽然?


此外,这听起来像是涉及到实现Python的库

,目前用C语言在Python中实现,因此它们可以是

已翻译。我是否正确地理解了这一点?

这个实现需要一个最小的核心,在一个名为rpython的python的受限制的子集中写入。这个子集避免了python的许多最动态的方面,通过使用顶级类型推理技术的工具,更容易通过自动将其转换为C语言。


好​​的,现在我理解这一点关于RPython,谢谢。

这个翻译版本的rpython解释器(已经自动翻译了
)到c),是Pypy的基础。


现在我再次感到困惑 - psyco将Python翻译成机器代码 - 所以

这是如何与译员写的事实相关的在

Python被翻译成另一种语言(在这种情况下是C?)

然而,我仍然怀疑我真的理解它...
我是'我还不确定是否会使用类型推断技术来提高在pypy上运行的程序的性能,或者这些技术是否仅用于将rpython解释器转换为c。

据我所知,pypy目前比使用cpython慢​​10/20倍,尽管仍有许多优化工作要做。
我不确定,但我认为它的开发人员依靠类似于psyco的技术来实现他们寻找的大速度提升。


这是另一个我没有得到的 - 这种方法似乎意味着当

PyPy合理完成时,预计它会' CP比赛要快得多。我的意思是,我不知道那些被翻译成C的东西可以比手写的C版更快吗?


谢谢,

Ray

Luis
So its author decided that having a python implementation written in
python would laid a much better basis for implementing psyco-like
techniques.
OK, so far I get it... I think. So it''s implementing the Python
interpreter in a Python subset called RPython, makes it more amenable
to translation with psyco-like techniques. But how is this superior
compared to CPython? Is it because Psyco is a specializer, which
generate potentially different code for different sets of data? So the
assumption is that the interpreter deals with a very specific set of
data that Psyco will be able to make use to generate very efficient
machine code?

I still don''t get how this can be superior to the hand-coded C version
though?

Also, this sounds like it involves implementing the Python''s libraries
that are currently implemented in C, in Python, so that they can be
translated. Did I get that correctly?
This implementation requires a minimal core, writen in a restricted
subset of python called "rpython". This subset avoids many of the most
dynamic aspects of python, making it easier to authomatically translate
it to C through a tool that uses top-notch type inference techniques.
OK, now I understand this bit about RPython, thanks.
This translated version of the rpython interpreter (which got already
auto-translated to c), is the basis of Pypy.
Now I''m confused again--psyco translates Python into machine code--so
how does this tie in with the fact that the interpreter written in
Python is translated into another language (in this case C?)
However, I still doubt that I really understood it...
I''m still not sure if the type inference techniques will be used to
improve the performance of programs running on pypy, or if these
techniques were only intended for getting the rpython interpreter
translated to c.

As far as I know, pypy is currently about 10/20 times slower than
cpython, although many optimizations remain to be done.
And I ''m not sure, but I think that its developers rely on the
psyco-like techniques to achieve the big speed boost their looking for.
This is another one I don''t get--this approach seems to imply that when
PyPy is reasonably complete, it is expected that it''ll be faster than
CPython. I mean, I don''t get how something that''s translated into C can
be faster than the handcoded C version?

Thanks,
Ray

Luis






Kevin Yuan写道:
Kevin Yuan wrote:


2005年12月21日19:33:20 -0800,LuisM.González< lu ***** @ gmail.com
< mailto:lu **** *@gmail.com>>:

......这个实现需要一个最小的核心,写在一个名为rpython的python的受限制的子集中。 。这个子集避免了python的许多最动态的方面,通过使用顶尖类型推理技术的工具,可以更容易地将它自动转换为C.

为什么不直接在C中写出最小的核心?


21 Dec 2005 19:33:20 -0800, Luis M. González <lu*****@gmail.com
<mailto:lu*****@gmail.com>>:

... ...
This implementation requires a minimal core, writen in a restricted
subset of python called "rpython". This subset avoids many of the most
dynamic aspects of python, making it easier to authomatically translate
it to C through a tool that uses top-notch type inference techniques.
Why not directly write the minimal core in C?



因为那时你必须用C维护它。这样,一旦你有了

第一个工作翻译你可以把它翻译成C来提高它的b / b
性能,用它来翻译* next * working translator,和

等等。因此,您的维护工作是在Python代码上完成的,而不是手工翻译的C.


相当标准的自举技术,虽然它有时很难

来理解在X中编写语言X的编译器所涉及的问题

。典型的是m版本的编译器必须以版本(m-1)编写
,例如:-)


used-to -do-that-for-a-living-ly y''rs - 史蒂夫

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC www.holdenweb.com

PyCon TX 2006 www.python.org/pycon/


Because then you''d have to maintain it in C. This way, once you have the
first working translator you can translate it into C to improve its
performance, and use it to translate the *next* working translator, and
so on. Consequently your maintenance work is done on the Python code
rather than hand-translated C.

Fairly standard bootstrapping technique, though it''s sometimes difficult
to appreciate the problems involved in writing a compiler for language X
in X itself. Typical is the fact that the compiler for version m has to
be written in version (m-1), for example :-)

used-to-do-that-stuff-for-a-living-ly y''rs - steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/


这篇关于关于PyPy请告诉我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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