| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
ZeroconfIPv4Address/ZeroconfIPv6Address assigned self.__hash__ to a functools.cache(lambda ...) in __init__. Because __hash__ sat in __slots__ the memoization did work, but every address object paid to build a full lru_cache wrapper plus a self-capturing lambda at construction time (and a self -> slot -> wrapper -> lambda -> self reference cycle for the GC to reap). Compute the hash once into a plain int slot and expose it through a real __hash__ method. Construction drops ~25-45% in pure-Python micro- benchmarks; hash() stays memoized via the precomputed slot.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## master #1774 +/- ##
=======================================
Coverage 99.77% 99.77%
=======================================
Files 33 33
Lines 3536 3540 +4
Branches 498 498
=======================================
+ Hits 3528 3532 +4
Misses 5 5
Partials 3 3 ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
Merging this PR will improve performance by 48.56%⚠️ Different runtime environments detected
⚡ 2 improved benchmarks Performance Changes
Tip Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent. Comparing bluetoothbot:koan/fix-ipaddress-hash-caching (7f7eea6) with master (bd20c8e) |
Sorry, something went wrong.
|
good fix, but can't merge it because we are out of space on pypi. it has to wait a week or so |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
What
Replace the per-instance functools.cache(lambda ...) assigned to self.__hash__ in ZeroconfIPv4Address / ZeroconfIPv6Address with a hash precomputed once into an int slot, exposed through a real __hash__ method.
Why
Same class of bug as Bluetooth-Devices/cached-ipaddress#108. The old code did:
Because __hash__ was listed in __slots__, the memoization did take effect here (unlike the cached-ipaddress case, where it was dead code). But every address object still paid to allocate a full lru_cache wrapper and a self-capturing lambda at construction, plus created a self → slot → wrapper → lambda → self reference cycle the GC has to collect. get_ip_address_object_from_record builds one of these per A/AAAA record on a cache miss, so the construction cost is on the discovery hot path.
How
No cdef class declaration for these types in ipaddress.pxd, so they stay pure-Python classes under the Cython build; cython -3 compiles the module cleanly.
Testing
Quality Report
Changes: 3 files changed, 75 insertions(+), 5 deletions(-)
Code scan: clean
Tests: passed (4 PASSED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline