[pypy-dev] Safety of replacing the instance dict

Antonio Cuni anto.cuni at gmail.com
Tue Jan 30 07:13:19 EST 2018


sidenote: if you do the following, you can replace the __dict__ without
incurring into performance penalties (Armin, please correct me if I'm
wrong):

import __pypy__
def __init__(self):
    self.__dict__ = __pypy__.newdict('instance')

this is not directly useful for your use case (because newdict() always
return an empty dict), but it might be useful to know in general

On Mon, Jan 29, 2018 at 1:41 PM, Armin Rigo <armin.rigo at gmail.com> wrote:

> Hi,
>
> On 29 January 2018 at 11:22, Tin Tvrtković <tinchester at gmail.com> wrote:
> > It's just that doing it this way is unconventional and a little scary.
> Would
> > we be violating a Python rule somewhere and making stuff blow up later
> if we
> > went this way?
>
> No, it's semantically fine.  But it comes with a heavy penalty on
> PyPy.  I guess you don't see it because you measured something tiny,
> like creating the instance and then throwing it away---the JIT
> optimizes that to nothing at all in both cases.  Not only is the
> creation time larger, but attribute access is slower, and the memory
> usage is larger.
>
>
> A bientôt,
>
> Armin.
> _______________________________________________
> pypy-dev mailing list
> pypy-dev at python.org
> https://mail.python.org/mailman/listinfo/pypy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20180130/455c1cf9/attachment.html>


More information about the pypy-dev mailing list