Seth Bromberger added the comment: As a test, I tried the following (taken mostly from http://codesnipers.com/?q=python-flyweights):
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): pass 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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23103> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com