Raihan Rasheed Apurbo wrote: > In CPython we have reference counting. My question is can we optimize current > RC using > strategies like Deferred RC and Coalescing?
You might also look at some of the older attempts to remove reference counting entirely in favor of (usually) the Boehm tracing collector. The "problem" is that adding 1 to an integer that is already in cache is pretty quick. The same goes for subtracting 1. So to beat the current system, you need something very fast *and* you need to take out some cost that isn't directly part of reference counting. If you're assuming multiple threads (or processes) on different cores, that is possible. You know about the Gilectomy by now. I suspect that splitting the reference count away from the object itself could also be profitable, as it means the cache won't have to be dirtied (and flushed) on read access, and can keep Copy-On-Write from duplicating pages. On the other hand, it also means that you'll (eventually, after your optimization strategies) have to issue extra loads for the reference count, instead of getting it into cache for free when you load the data. > If no then where would I face problems if I try to implement these sorts of > strategies? The current system is really very fast, particularly in a single-threaded environment. You probably won't see enough gains to make up for the complexity unless you do also reorganize memory. That isn't easy to do in incremental steps, or in a backwards-compatible way. But looking at how PyPy organizes its memory models may provide a rough map of something that works. (Or warn you of what doesn't work, if they say "can't use this model when using extension modules.") > These strategies all depend on the concept that we don't need the exact value > of > reference count all the time. So far in my observation, we only need exact > value before > running a cycle collector. We also need to be sure the estimate is never too low, or at least that it never goes negative, and that it never hits 0 when it shouldn't. Being too high is fine, but it may lead to using a surprisingly large amount of extra memory, and breaking out of cache more often. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/CRRUXXHEULAH4YXMYOJNZEPU5U6LUUSH/ Code of Conduct: http://python.org/psf/codeofconduct/