On Fri, Jun 19, 2020 at 09:36:24AM +0100, Jonathan Fine wrote:
> What I did not say explicitly, or not clearly enough, was that the previous
> use would continue unchanged. The only change would be that a function
> object would have a flag, which would tell the interpreter whether the
> associated code object was transient or permanent. (This, as I recall, I
> did mention in my original post.)
Who sets the flag?
If user code can set the flag, then users can maliciously or
accidentally set the flag on code objects which should be garbage
collected, causing a memory leak, or clear the flag on code objects
which should not be garbage collected, potentially causing a segfault.
I think that if anyone is imagining a process where the interpreter does
something like this:
# this happens on every single reference to any object
if type(obj) is a code object and flag is set:
pass
else:
increment the reference count
(and similar for decrements) the cost of checking the type and/or flag
is going to be significant. According to issue 40255, a similar
experiment lead to a 10% slowdown.
https://bugs.python.org/issue40255
There are more practical ways to implement immortal objects. I don't
know what they are :-) but they must exist because Python had them
before (and maybe still does?) and people keep experimenting with them.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/EIU6NZPHF5CDJV64YAKLQZTB5SXMLUU7/
Code of Conduct: http://python.org/psf/codeofconduct/