Render MAC addresses with bytes.hex(":") - #117
Merged
Merged
Conversation
bytes_to_mac built each address with ":".join(format(o, "02x") for o in data) -- seven generator steps and six format() calls per address, twice per Ethernet frame, plus once per ARP hardware address and NDP link-layer option. A corpus profile attributed 88,200 generator calls and 75,600 format() calls to it. bytes.hex() has taken a separator since 3.8 and does the whole thing in one C call: 16-29x faster on the call depending on run. Output is byte-for-byte identical, verified against the old implementation for both bytes and memoryview input -- memoryview.hex also takes a separator, so the decode-time view path is unaffected. Closes#83 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QJnVMNGwTRDktC4rkABtgt
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes#83. First of Tier 1 (#103).
bytes_to_macbuilt each address with":".join(format(octet, "02x") for octet in data)— seven generatorsteps and six
format()calls per address, twice per Ethernet frame,plus once per ARP hardware address and NDP link-layer option. A corpus
profile attributed 88,200 generator calls and 75,600
format()calls to it.
bytes.hex()has taken a separator argument since Python 3.8 and doesthe whole thing in one C call.
What's included
src/netprotocols/_base.py— one line, plus a comment recording why.CHANGELOG.md— entry under## [Unreleased]→### Changed.Verification
uv run ruff checkanduv run ruff format --checkare cleanuv run mypyis clean (strict)uv run pytestpasses — 749 tests, coverage 99.79%CHANGELOG.mdhas an entry under## [Unreleased]Output checked against the old implementation, for both input types the
decode path can produce:
The
memoryviewcase matters becausedecode()accepts a view and theold generator iterated it happily.
memoryview.hexalso takes aseparator, so that path is unaffected — no
bytes()coercion needed.Speed, 300,000 calls:
#82 measured this at 16.5× on an earlier run; the direction is
unambiguous but the multiple varies, so the changelog cites the range
rather than the flattering number. Its contribution to end-to-end decode
throughput is ~0.9 µs/frame — real but small next to #82's dispatch
fix. The combined figure gets measured properly by the harness in #86.
Notes
Taken ahead of #82 deliberately: #103 records the two as independent and
order-independent, and this one is a single line with a clean
equivalence check. #82 is the larger win (91×/42× on dispatch) and the
one that shares a design with the registry in #87, so it deserves more
room than was left in this session.
No API change; nothing outside
_base.pymoves.🤖 Generated with Claude Code
https://claude.ai/code/session_01QJnVMNGwTRDktC4rkABtgt
Generated by Claude Code