Skip to content

P4: performance — passkey allocations, walk delegation, socket reuse - #27

Merged
stakach merged 3 commits into
spider-gazelle:masterfrom
n-rodriguez:feat/p4-perf
Jul 12, 2026
Merged

P4: performance — passkey allocations, walk delegation, socket reuse#27
stakach merged 3 commits into
spider-gazelle:masterfrom
n-rodriguez:feat/p4-perf

Conversation

@n-rodriguez

Copy link
Copy Markdown
Contributor

The P4 (performance) group from the audit (#7). One commit per item.

Commits

  1. perf(v3): avoid per-iteration String allocation in passkey — the RFC 3414 key expansion looped 16384 times allocating two Strings each iteration (a rotated password copy + a 64-byte tiling). It now feeds the digest a single reused Bytes(64) buffer indexed cyclically.
    • ⚠️ The password is now indexed per octet (as RFC 3414 specifies) rather than per character — identical for ASCII passwords (all real SNMP secrets), a correctness fix for non-ASCII ones. The RFC A.2.1 vectors are verified byte-identical.
  2. refactor(client): delegate the array walk to the block form — the non-block walk duplicated the block form's loop; it now delegates, and documents that it buffers the whole subtree (prefer the block form or #bulk_walk to stream).
  3. perf(client): reuse the UDP socket across requestswith_socket connected a fresh socket and closed it on every operation, churning sockets and changing the source port each call. The socket is now connected on first use and reused; reset only on error. Adds Client#close and a note that a Client is not safe for concurrent use.

Tests

The passkey change is guarded byte-for-byte by the RFC 3414 A.2.1 vectors (security_spec). The walk delegation is behaviour-preserving. Socket reuse is transport glue, exercised by the e2e suite. Deterministic 82/82, multi-threaded 82/82, legacy 3/3, ameba clean, format clean; commits bisect-clean.

Tracked in #7.

🤖 Generated with Claude Code

n-rodriguez and others added 3 commits July 12, 2026 05:01
The RFC 3414 key expansion looped 16384 times, allocating two Strings per
iteration (a rotated copy of the password + a 64-byte tiling). Feed the digest a
single reused 64-byte buffer indexed cyclically instead.

- v3/security: passkey builds one Bytes(64) buffer, no per-iteration allocation

NOTE: the password is now indexed per octet (RFC 3414 operates on octets) rather
than per character; identical for ASCII passwords (all real SNMP secrets), a
correctness fix for non-ASCII ones. RFC A.2.1 vectors verified byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The non-block walk duplicated the block form's loop. Delegate to it and document
that it buffers the whole subtree — prefer the block form or #bulk_walk to stream.

- client: walk(oid) : Array now calls walk(oid) { ... }

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
with_socket connected a fresh socket and closed it on every operation, churning
sockets and changing the source port each call. Keep one socket, connected on
first use and reused; reset it only on error.

- client: connected_socket / reset_socket; with_socket no longer closes on
  success; add Client#close and a not-concurrency-safe note

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stakach
stakach merged commit 5c94aea into spider-gazelle:master Jul 12, 2026
6 checks passed
@n-rodriguez
n-rodriguez deleted the feat/p4-perf branch July 12, 2026 23:22
@n-rodriguez
n-rodriguez restored the feat/p4-perf branch July 21, 2026 08:54
@n-rodriguez
n-rodriguez deleted the feat/p4-perf branch July 21, 2026 08:54
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