This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sbromberger
Recipients josh.r, lemburg, ncoghlan, pmoody, r.david.murray, rhettinger, sbromberger, serhiy.storchaka
Date 2014-12-23.23:18:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
As a test, I tried the following (taken mostly from

class Foo(object):
    _Foo = weakref.WeakValueDictionary()
    def __new__(cls, addr):
        obj = Foo._Foo.get(addr, None)
        if obj is None:
            obj = object.__new__(cls)
            Foo._Foo[addr] = obj
            obj.addr = addr
        return obj

I created 10 million instances of Foo(34) in an array. Total space taken: ~80 MB. Times: CPU times: user 6.93 s, sys: 48.7 ms, total: 6.98 s
Wall time: 6.98 s

I then created 10 million instances of a non-flyweight object, assigning an int to an instance variable:

class Bar(object):

Total space taken: ~1.4 GB. Times:
CPU times: user 7.64 s, sys: 794 ms, total: 8.44 s
Wall time: 8.44 s

This corresponds (roughly) to the space taken by 10 million IPAddr objects.

So it appears, informally, that caching / flyweight results in modest time and significant memory savings.

I understand that the ship has sailed for a stdlib implementation, but these results are compelling enough for me to create a separate package.
Date User Action Args
2014-12-23 23:18:35sbrombergersetrecipients: + sbromberger, lemburg, rhettinger, ncoghlan, pmoody, r.david.murray, serhiy.storchaka, josh.r
2014-12-23 23:18:35sbrombergersetmessageid: <>
2014-12-23 23:18:35sbrombergerlinkissue23103 messages
2014-12-23 23:18:35sbrombergercreate