[issue23103] ipaddress should be Flyweight

Seth Bromberger report at bugs.python.org
Tue Dec 23 14:52:14 CET 2014


Seth Bromberger added the comment:

>What is your proposal? WeakValueDictionary mapping raw bytes object to single instance of ipaddress that is queried from ipaddress's __new__? No built-in has quite that extensive a level of caching and aggressive deduplication to my knowledge.

I was thinking along those lines, but since v4 addresses are just UInt32 and v6 are UInt128, somehow mapping just the "address" information if we can do that via weakref dicts. Right now these objects can't really be used to represent addresses parsed from logs with tens of millions of entries generated by a couple thousand machines. It would be nice to have a memory-efficient way of doing that without having to duplicate the concept in a third-party package.

There are a few other changes I'd like to see/make as well - this package is too focused on external functions for manipulating/creating addresses, when standard object/method structure would serve it better and be more intuitive. There is also no discernible need to modify an IP address' value. They should be thought of as immutables to the extent we can enforce that policy.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23103>
_______________________________________


More information about the Python-bugs-list mailing list