On 14 December 2016 at 15:19, 张耀 <yzha...@corp.netease.com> wrote:
> Hi, every experts:
>    Recently I'm trying to move my old project from python to pypy.  In the 
> past, I have do some optimizations for python interpreter. One Important 
> thing is modify python default integer object cache range(default is from -5 
> to 257),  my config is  -100 to 1024 * 1024,  this range covers most of the 
> my app logics. The benchmark shows that it saves a lot of memory ,  and 
> speedup the program(mainly benefits from avoiding large amount of  creating 
> intobject and releasing intobject) .
>
>   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.
>

Allocating a new object in PyPy is faster to start with, especially
with the default GC, and because of the GC releasing short-lived
intobject costs nothing.  Additionally, there are lots of places where
ints do not need an object.  PyPy's specialised dictionary for laying
out class instances (mapdict) leaves only a platform integer in many
cases.  Similarly for lists, lists of just integers have a special
compact representation in a default PyPy build.  Hot loops also get
compiled, and any integers that don't escape the loop are unboxed and
need to object to represent them.

Prebuilt ints also have another cost that works against the layouts
and compiled code above:  everywhere an operation could produce a
prebuilt intobject, an extra conditional check has to be performed.
Having prebuilt integers turned off removes this condition from warm
code.

>   I check the pypy sourcecode, but I have not find out the problem so far. 
> So, my doubt is: why withprebuiltint option is off default?  Maybe the 
> performance is a problem as known?
>

Yes.  Prebuilt ints are only really an optimisation on CPython, PyPy
has better optimisations that work well with GC.

-- 
William Leslie

Notice:
Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely MAY reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to DENY YOU THOSE RIGHTS would be illegal without
prior contractual agreement.
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to