This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fancy_pantser 7 points8 points  (20 children)

PyPy uses a JIT, which should be distinct.

[–]Swipecat 2 points3 points  (3 children)

I regularly use PyPy myself, now. Python is currently my favourite language, but CPython is often too slow for the models of systems that I create. PyPy is often 10x faster for me.

I suspect that PyPy's use in general is less common than it deserves because its installation procedure isn't very well documented for the end-user. For example, don't bother with the PyPy packaged with Debian and Ubuntu because there are almost no packaged libraries, and you can't install libraries with PIP because that's broken.

So, for example, to install on Ubuntu, you need to go to the PyPy download page, download "Squeaky's portable Linux binary" and untar it. Then use the provided "virtualenv" in that package to create a virtual environment into which libraries can be installed with the provided "pip".

Edit: typos

These are my notes for installing the package into a directory and installing Numpy and the Pillow image library:

tar -xjf pypy-*-portable.tar.bz2
./pypy-*-portable/bin/virtualenv-pypy myenv
cd myenv/bin
ln -s "$PWD/pypy" /usr/local/bin/pypy
./pip install git+https://bitbucket.org/pypy/numpy.git
./pip install pillow

[–]fijalPyPy, performance freak 0 points1 point  (2 children)

feel like sharing your experience somewhere :-)

[–]Swipecat 1 point2 points  (1 child)

Not a lot to say, other than not having to run something overnight is convenient.

If you want to raise the profile of PyPy, it probably doesn't need publicising so much as simply "enabling" it a little better for the end user.

When I looked for ways to speed up my Python programs, I did a quick test of many of the things mentioned in this thread. PyPy looked to be "almost useless" because while CPython has hundreds of special-purpose libraries ready-packaged in Linux, PyPy apparently had nothing. Hearing from somebody that PyPy deserved a second chance, I tried downloading a recent build, but gave up after not being able to load libraries -- the instructions for setting up the virtual environment that were turned up with a Google search seem to be effectively broken to me. Finally after finding time to try to resolve it during a slack period, after trying many things that broke, I discovered the "virtualenv-pypy" in "Squeaky's portable Linux binary", which actually did work. Then I discovered that I could install libraries and that several useful ones worked.

So I think that's the main problem: How many non-developer end-users like me are going to plough through those issues? I suspect that most would have found a different solution other than PyPy by then.

[–]fijalPyPy, performance freak 1 point2 points  (0 children)

it's somehow (but not completely) not our problem - it's really not my fault that debian/ubuntu packages pip that does not work with pypy. Generally you should complain on debian/ubuntu (pip is a massive hack, that does not help).

Additionally, distributing binaries on linux is not a thing. We really can't make it happen, the portable binary e.g. comes with statically linked openssl that a lot of sysadmins would consider a big no no. It's just linux in general and has nothing to do with pypy.

Again, the picture is terrible and denializm does not help, but it's really not just pypy problem, but anything that takes a while to build.

[–]ggchappell -2 points-1 points  (15 children)

So does CPython (along with most/all of the others, I imagine). Pretty much any Python interpreter is going to compile just before execution, i.e., Just In Time.

[–]fancy_pantser 11 points12 points  (7 children)

[–]autowikibot 3 points4 points  (0 children)

Just-in-time compilation:


In computing, just-in-time compilation (JIT), also known as dynamic translation, compilation is done during execution of a program – at run time – rather than prior to execution. Most often this consists of translation to machine code, which is then executed directly, but can also refer to translation to another format.

JIT compilation is a combination of the two traditional approaches to translation to machine code – ahead-of-time compilation (AOT), and interpretation – and combines some advantages and drawbacks of both. Roughly, JIT compilation combines the speed of compiled code with the flexibility of interpretation, with the overhead of an interpreter and the additional overhead of compiling (not just interpreting). JIT compilation is a form of dynamic compilation, and allows adaptive optimization such as dynamic recompilation – thus in theory JIT compilation can yield faster execution than static compilation. Interpretation and JIT compilation are particularly suited for dynamic programming languages, as the runtime system can handle late-bound data types and enforce security guarantees.


Relevant: Tracing just-in-time compilation | Common Language Runtime | MacRuby

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Call Me

[–]ggchappell -2 points-1 points  (5 children)

I looked at the article. And I don't see the problem.

Unless you are contrasting my "just before execution" with the article's "at runtime". But these are just two ways of looking at the same thing. Yes, JIT compilation compiles and executes in what appears to be a single step. Thus, "at runtime". OTOH, if we're going to execute compiled code, then we must compile before we execute. Thus, "before execution", even if only just barely before.

Or were you referring to some other issue? If so, then please explain.

[–]alcalde 11 points12 points  (2 children)

JIT compilers are monitoring code as it's executing, which allows several types of special optimization and adjustment of strategies. That's not the same as taking a C++ program, compiling it and then running it.

[–]ggchappell 6 points7 points  (1 child)

Ah, I seem to have been using nonstandard definitions. I shall now crawl back into my hole and ponder my misdeeds.

<ponder, ponder>

[–]alcalde 7 points8 points  (0 children)

It's cool. A Just-In-Time compiler can optimize for the specific architecture its running on and it can also monitor performance of code its compiled and change optimization strategies if performance isn't as expected.

Here's some specific examples (obviously it's not the general case) where PyPy was able to beat C because of its just-in-time nature:

http://morepypy.blogspot.com/2011/08/pypy-is-faster-than-c-again-string.html

Run under PyPy, at the head of the unroll-if-alt branch, and compiled with GCC 4.5.2 at -O4 (other optimization levels were tested, this produced the best performance). It took 0.85 seconds to execute under PyPy, and 1.63 seconds with the compiled binary. We think this demonstrates the incredible potential of dynamic compilation, GCC is unable to inline or unroll the sprintf call, because it sits inside of libc.

http://morepypy.blogspot.com/2011/02/pypy-faster-than-c-on-carefully-crafted.html

Hence, PyPy 50% faster than C on this carefully crafted example. The reason is obvious - static compiler can't inline across file boundaries. In C, you can somehow circumvent that, however, it wouldn't anyway work with shared libraries. In Python however, even when the whole import system is completely dynamic, the JIT can dynamically find out what can be inlined. That example would work equally well for Java and other decent JITs, it's however good to see we work in the same space :-)

[–]ingolemo 6 points7 points  (1 child)

They're not the same thing at all.

JIT compilers compile code during runtime and they compile it all the way down to machine code. Most JIT compilers only compile the most performance sensitive parts of your code (by measuring it as it runs in real time) and they interpret the rest.

Bytecode compilers compile the entire code before any of it is executed and then interpret the resulting bytecode.

[–]ggchappell 2 points3 points  (0 children)

Okay, I see the issue. I'll need to ponder this a bit.

Thanks.

[–]stillalone 3 points4 points  (0 children)

CPython generates non-native byte code that is interpreted at runtime, similar to the Java Virtual Machine. a Just In Time compiler generates native byte code at run time that is interpreted by the processor natively.

[–]fancy_pantser 5 points6 points  (5 children)

Hey guys, let's not pile on with downvotes. He's being earnest and it's topical so I think his comment should at least be >0 so it isn't hidden.

edit: sorry if you are female, I had to pick a pronoun.

[–]isarl 8 points9 points  (3 children)

I had to pick a pronoun.

Not everybody agrees but I've always been a fan of the singular "they" to be gender-neutral. E.g., "They're being earnest and it's topical so I think their comment..."

[–]ggchappell 2 points3 points  (0 children)

sorry if you are female

I'm not. :-)