Skip to content

test: add benchmarks for ipaddress object creation and hashing#1773

Merged
bdraco merged 1 commit into
python-zeroconf:masterfrom
bluetoothbot:koan/bench-ipaddress-creation
May 24, 2026
Merged

test: add benchmarks for ipaddress object creation and hashing#1773
bdraco merged 1 commit into
python-zeroconf:masterfrom
bluetoothbot:koan/bench-ipaddress-creation

Conversation

@bluetoothbot
Copy link
Copy Markdown
Contributor

What

Add CodSpeed benchmarks for ZeroconfIPv4Address / ZeroconfIPv6Address construction and hashing.

Why

get_ip_address_object_from_record builds one of these objects per A/AAAA record on a cache miss, and the objects are hashed when stored in sets/dicts. There is currently no benchmark guarding the construction or hash cost of this hot path, so regressions (or improvements) go unmeasured.

This establishes the baseline before a follow-up that reworks how the per-instance hash is cached.

How

Four benchmarks under tests/benchmarks/test_ipaddress.py:

  • construct 1000 distinct IPv4 / IPv6 address objects (__init__ cost)
  • hash a warm IPv4 / IPv6 address 1000× (memoized-hash cost)

Testing

SKIP_CYTHON=1 poetry run pytest tests/benchmarks/test_ipaddress.py -v — 4 passed. ruff + ruff-format clean.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.77%. Comparing base (cb81e67) to head (433dd40).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1773   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files          33       33           
  Lines        3536     3536           
  Branches      498      498           
=======================================
  Hits         3528     3528           
  Misses          5        5           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 24, 2026

Merging this PR will not alter performance

✅ 14 untouched benchmarks
🆕 4 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_create_ipv4_addresses N/A 36.4 ms N/A
🆕 test_create_ipv6_addresses N/A 45.2 ms N/A
🆕 test_hash_ipv4_address N/A 515.8 µs N/A
🆕 test_hash_ipv6_address N/A 515.8 µs N/A

Comparing bluetoothbot:koan/bench-ipaddress-creation (433dd40) with master (cb81e67)

Open in CodSpeed

@bdraco bdraco marked this pull request as ready for review May 24, 2026 19:20
@bdraco bdraco merged commit bd20c8e into python-zeroconf:master May 24, 2026
36 checks passed
@bluetoothbot bluetoothbot deleted the koan/bench-ipaddress-creation branch May 24, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants