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.
Created on 2014年05月12日 18:24 by pitrou, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| v4_netmask.patch | pitrou, 2014年05月12日 18:24 | review | ||
| netmask.patch | pitrou, 2014年05月12日 18:57 | review | ||
| Messages (8) | |||
|---|---|---|---|
| msg218344 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年05月12日 18:24 | |
Here is a patch to optimize ipv4 netmask parsing by maintaining a cache (there are not many valid ipv4 netmask representations). This should be especially useful with #16531. |
|||
| msg218349 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年05月12日 18:57 | |
Updated patch, also optimizing v6 netmask parsing (same principle).
Before patch:
$ ./python -m timeit -s "import ipaddress" "net = ipaddress.IPv6Network(('2001:db8::', 96))"
10000 loops, best of 3: 26.1 usec per loop
$ ./python -m timeit -s "import ipaddress" "net = ipaddress.IPv4Network(('10.0.0.0', 23))"
100000 loops, best of 3: 17 usec per loop
After patch:
$ ./python -m timeit -s "import ipaddress" "net = ipaddress.IPv6Network(('2001:db8::', 96))"
100000 loops, best of 3: 13.8 usec per loop
$ ./python -m timeit -s "import ipaddress" "net = ipaddress.IPv4Network(('10.0.0.0', 23))"
100000 loops, best of 3: 14.3 usec per loop
|
|||
| msg218481 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年05月13日 20:03 | |
Why not just use functools.lru_cache? |
|||
| msg218482 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年05月13日 20:04 | |
Because that would incur the cost of LRU logic and locking, which we don't need here. |
|||
| msg218504 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年05月14日 06:33 | |
With C implementation (issue14373) functools.lru_cache is so fast as manually written specialized code. |
|||
| msg218609 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年05月15日 12:43 | |
What I want to say, the patch LGTM, but after committing issue14373 we should simplify the code by using functools.lru_cache(). |
|||
| msg218610 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年05月15日 12:49 | |
Actually, using lru_cache(maxsize=None) would enable a simple infinite cache like in the patch. But it's not like a lot of code would be saved. |
|||
| msg218621 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2014年05月15日 18:19 | |
New changeset 2158614e1607 by Antoine Pitrou in branch 'default': Issue #21486: Optimize parsing of netmasks in ipaddress.IPv4Network and ipaddress.IPv6Network. http://hg.python.org/cpython/rev/2158614e1607 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:03 | admin | set | github: 65685 |
| 2014年05月15日 19:06:11 | pitrou | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2014年05月15日 18:19:51 | python-dev | set | nosy:
+ python-dev messages: + msg218621 |
| 2014年05月15日 12:49:10 | pitrou | set | messages: + msg218610 |
| 2014年05月15日 12:43:42 | serhiy.storchaka | set | messages: + msg218609 |
| 2014年05月14日 06:33:22 | serhiy.storchaka | set | messages: + msg218504 |
| 2014年05月13日 20:04:50 | pitrou | set | messages: + msg218482 |
| 2014年05月13日 20:03:00 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg218481 |
| 2014年05月12日 18:57:34 | pitrou | set | files:
+ netmask.patch messages: + msg218349 title: optimize v4 netmask parsing -> optimize v4 & v6 netmask parsing |
| 2014年05月12日 18:24:56 | pitrou | set | dependencies: + Allow IPNetwork to take a tuple |
| 2014年05月12日 18:24:45 | pitrou | create | |