Skip to content

Render MAC addresses with bytes.hex(":") - #117

Merged
EONRaider merged 1 commit into
masterfrom
claude/decoder-depth-polish-8m54to
Sep 1, 2026
Merged

Render MAC addresses with bytes.hex(":")#117
EONRaider merged 1 commit into
masterfrom
claude/decoder-depth-polish-8m54to

Conversation

@EONRaider

Copy link
Copy Markdown
Owner

Summary

Closes#83. First of Tier 1 (#103).

bytes_to_mac built each address with
":".join(format(octet, "02x") for octet 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 argument since Python 3.8 and does
the 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 check and uv run ruff format --check are clean
  • uv run mypy is clean (strict)
  • uv run pytest passes — 749 tests, coverage 99.79%
  • CHANGELOG.md has an entry under ## [Unreleased]

Output checked against the old implementation, for both input types the
decode path can produce:

bytes '00:07:0d:af:f4:54' identical=True
memoryview '00:07:0d:af:f4:54' identical=True

The memoryview case matters because decode() accepts a view and the
old generator iterated it happily. memoryview.hex also takes a
separator, so that path is unaffected — no bytes() coercion needed.

Speed, 300,000 calls:

old 0.418s new 0.014s -> 29.5x

#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.py moves.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QJnVMNGwTRDktC4rkABtgt


Generated by Claude Code

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
@EONRaider
EONRaider merged commit 7737a85 into masterSep 1, 2026
6 checks passed
Sign up for freeto 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.

Render MAC addresses with bytes.hex(":")

2 participants

@EONRaider@claude