Gregory P. Smith <g...@krypto.org> added the comment:

Thanks for sharing!  It's good to have a patch implementing for others who 
might need it to try out.

We experimented with an implementation of this on CPython 2.7 that we called 
Eternal Refcounts for YouTube many years ago.  For the same reason (saving 
memory in forked workers by not dirtying pages of known needed objects via 
refcount changes).

I don't have that old patch handy right now, but looking at yours it was the 
same concept: A magic refcount value to branch based on.

We wound up not deploying it or pushing for it in CPython because the CPU 
performance implications of adding a branch instruction to Py_INCREC and 
Py_DECREF were, unsurprisingly, quite high.  I'd have to go digging to find 
numbers but it _believe_ it was on the order of a 10% slowdown on real world 
application code.  (microbenchmarks don't tell a good story, the python 
performance test suite should)

Given that most people's applications don't fork workers, I do not expect to 
see such an implementation ever become the default.  It is a very appropriate 
hack, but the use case is limited to applications that don't use threads, are 
on POSIX, and always fork() many workers.

Also note that this is an ABI change as those INCREF and DECREF definitions are 
intentionally public .h file macros or inlines and thus included within any 
compiledcode rather than being an expensive function call elsewhere (vstinner's 
new alternate higher level API proposal presumably changes this).  If an 
interpreter with this loaded a binary using the CPython API built against 
headers without it, your refcounts could get messed up.

----------
nosy: +gregory.p.smith
type:  -> enhancement

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40255>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to