Gregory P. Smith <[email protected]> added the comment:
[data] I finally dug up the old YouTube doc at work with their findings. Mostly
just posting this here for future public reference if anyone wants. Nothing
surprising.
When youtube experimented with a modified 2.7 adding "eternal refcounts" in
2015, they saw a 3-5% CPU performance regression. (not the 10% I had in my mind)
Their version of this simply set a high bit on the refcount as the indicator
and added the obvious conditional into the Py_INCREF/Py_DECREF macros.
Unsurprisingly in line with what others have since found. For their preforked
server and decision of what to mark eternal before forking, it saved them 10%
ram (fewer copy on writes). The -ram vs +cpu +maintenance cost tradeoff wound
up not being worthwhile to them though. Their motivation for trying was
entirely COW memory savings.
=== CPython 2.7 object.h modification they used:
```
+#ifdef GOOGLE_ETERNAL_REFCOUNT_SUPPORT
+
+#define PY_ETERNAL_REFCOUNT (PY_SSIZE_T_MAX / 2)
+
+#define Py_IS_ETERNAL(op) ( \
+ ((PyObject*)(op))->ob_refcnt >= PY_ETERNAL_REFCOUNT)
+
+#define Py_SET_ETERNAL(op) \
+ do { \
+ ((PyObject*)(op))->ob_refcnt = PY_ETERNAL_REFCOUNT; \
+ if (PyObject_IS_GC(op)) { \
+ PyObject_GC_UnTrack(op); \
+ } \
+ } while (0)
+
+#define Py_INCREF(op) ( \
+ Py_IS_ETERNAL(op) \
+ ? PY_ETERNAL_REFCOUNT \
+ : (_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ ((PyObject*)(op))->ob_refcnt++) \
+ )
+
+#define Py_DECREF(op) \
+ do { \
+ if (Py_IS_ETERNAL(op)) break; \
+ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ --((PyObject*)(op))->ob_refcnt != 0) \
+ _Py_CHECK_REFCNT(op) \
+ else \
+ _Py_Dealloc((PyObject *)(op)); \
+ } while (0)
+
+#else
```
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40255>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com