Commit 70c796b
perf: cache parsed ipaddress objects to avoid redundant string parsing
For first-occurrence IPs, the allocator constructs ipaddress.ip_network()
objects from formatted strings (e.g., "10.1.1.5/24"). When multiple hosts
share the same inferred /24 subnet, this string formatting and parsing
was repeated unnecessarily.
Add _parsed_networks dict to cache ip_network() results in both
_allocate_network() and _allocate_host() cold paths. Provides a
constant-factor improvement on top of the algorithmic gains.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 35e5a7f commit 70c796b
1 file changed
Lines changed: 15 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
| |||
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
| |||
134 | 140 | | |
135 | 141 | | |
136 | 142 | | |
137 | | - | |
138 | | - | |
139 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
140 | 148 | | |
141 | 149 | | |
142 | 150 | | |
| |||
0 commit comments