Hi,

On 14 December 2016 at 05:19, 张耀 <yzha...@corp.netease.com> wrote:
>   BUT, in pypy, I found the withprebuiltint option is set off default. While 
> I tried open this option and add translateoption : --prebuiltintfrom -5  
> --prebuiltintfrom 1048576, the benchmark shows that it saves memory(OK, it's 
> expected), BUT the speed is SLOWER.

The topic of this message says it all:

> why withprebuiltint option is off default? The speed is slower after I open 
> it.

That's why it is off by default: because it is slower.  PyPy differs
from CPython in two important aspects: it has a GC that is well-tuned
to creating and freeing objects at a high frequency; and it has a JIT
compiler that is able to remove allocations.  Each of these points
alone makes this optimization worthless (and others too).

In your trivial benchmark, all the integer objects are removed by the
JIT compiler, because it notices that they are created and then
forgotten very soon.  The machine code "explodes" the objects into a
single register each, which contains the integer value; this gives
basically C-like performance.  By contrast, if you enable
--withprebuiltint, then the code is much slower: it needs to add
checks that the numbers are within the specified range, and if they
are it needs to load the prebuilt objects' addresses and manipulate
them.  That's nonsense for JIT-generated machine code, and that's why
it is disabled by default.  It is only useful if you want to
absolutely minimize memory usage (in which case you make a slow pypy
with no JIT at all, with ``-Omem``).

In theory we could experiment with enabling ``--withprebuiltint`` only
when the JIT is not running.  But I strongly suspect that it is not
faster even without the JIT---our GC is good at that job.  Try to run
your benchmark with ``pypy --jit off``?


A bientôt,

Armin.
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to