[Python-Dev] RE: [Python-checkins] python/dist/src/Objects typeobject.c, 2.244, 2.245 (original) (raw)

Guido van Rossum guido at python.org
Fri Oct 24 11:59:04 EDT 2003


> PyINCREF(PyTrue); > return PyTrue; > > takes less time than > > return PyBoolFromLong(1); > > Maybe a pair of macros PyreturnTrue and PyreturnFalse would make > sense?

Sorry if this was already suggested and hastily rejected, but why do we care at all about the reference counter of the few heavily-used immortal objects of CPython?

It was never discussed; I don't recall that it has ever occurred to me.

I guess allowing their counter not to be carefully maintained ventures to the slippery slopes of bad code. Anyway, my two cents for a (very) slightly faster and shorter code would be to be allowed never to do PyINCREF or PyDECREF when we know that the object is PyNone, PyFalse or PyTrue. These three would have a dummy tpdealloc that just resets the reference counter to some large value if it ever reaches zero.

I think there are debugging modes where this would upset some counters that maintain a balance of the total number of references in the world.

I also don't think that the performance ggain would be measurable.

Maybe the slight code size decrease would have some benefits.

I'm worried that there would be a negative effect in terms of people copying the pattern for other objects.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list