Skip to content

Vectorize bit packing and remove the payload clone from ring sends - #140

Merged
philsippl merged 1 commit into
mainfrom
codex/threshold-buffer-reuse
Aug 24, 2026
Merged

Vectorize bit packing and remove the payload clone from ring sends#140
philsippl merged 1 commit into
mainfrom
codex/threshold-buffer-reuse

Conversation

@philsippl

Copy link
Copy Markdown
Contributor

Stacked on #138. Two allocation/copy reductions in the exact-scan threshold hot path. Wire format is byte-identical; no protocol changes.

What

  1. pack_bits / unpack_bits: were scalar per-bit loops with per-bit index arithmetic and bounds-checked writes; now process a byte (8 bits, LSB-first exactly as before) per step.
  2. send_ring_vec payload clone: it cloned the entire payload Vec into an owned NetworkValue, which the striped transport then serialized again into its wire buffer — two full copies per protocol message. A new NetworkValue::PreFramed variant carries the message already in wire format (serialized once from the borrowed slice), and the striped send consumes it via the new into_network() without re-serializing. PreFramed never appears on the wire as itself; into_vec/unpack_bits decode it transparently, so in-process LocalNetworking paths are unaffected.

Why / measured

Profiling the iris-mpc CPU linear scan on 3× r8g.24xlarge (1M records, both orientations), the threshold side paces the whole request and spends ~11% of its cycles in memcpy and ~6% in pack_bits. With this change the end-to-end scan goes from 6.33M to 6.47M comparisons/s (331.5 → 324.5 ms/request), measured with worldcoin/iris-mpc#2348.

Validated: crate test suite, the full iris-mpc-cpu suite against the patched crate, and the 3-node TCP e2e (striped TLS transport, mirror detection) with cross-party agreement.

🤖 Generated with Claude Code

dkales
dkales previously approved these changes Aug 17, 2026

@dkales dkales left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does what it says, but is a bit crude IMO
Might be worth investigating if the serialization can work like this in general for all types

@philsippl
philsippl force-pushed the codex/cpu-linear-scan-primitives branch from b1ffb57 to a558365 Compare August 24, 2026 12:48
Base automatically changed from codex/cpu-linear-scan-primitives to main August 24, 2026 12:56
@philsippl
philsippl dismissed dkales’s stale review August 24, 2026 12:56

The base branch was changed.

Two allocation/copy reductions in the exact-scan threshold hot path,
both byte-identical on the wire:

- pack_bits/unpack_bits packed one bit per iteration with per-bit index
  arithmetic and bounds checks; they now process a byte (8 bits,
  LSB-first as before) per step.
- send_ring_vec cloned the whole payload Vec into an owned NetworkValue,
  which the striped transport then serialized again into its wire
  buffer - two full copies per protocol message. A PreFramed NetworkValue
  variant carries the message already in wire format (serialized once
  from the borrowed slice), and the striped send consumes it via
  into_network() without re-serializing. PreFramed never appears on the
  wire as itself; into_vec/unpack_bits decode it transparently so
  in-process LocalNetworking paths are unaffected.

Measured on the iris-mpc CPU linear scan (3x r8g.24xlarge, 1M records):
these were ~11% memcpy + ~6% pack_bits of threshold-side cycles; the
change is worth ~2% end-to-end there (6.33M -> 6.47M comparisons/s).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@philsippl
philsippl force-pushed the codex/threshold-buffer-reuse branch from 2053bb6 to bb7ee68 Compare August 24, 2026 13:11
@philsippl
philsippl enabled auto-merge (squash) August 24, 2026 13:14
@philsippl
philsippl merged commit 11bcd05 into main Aug 24, 2026
13 of 14 checks passed
@philsippl
philsippl deleted the codex/threshold-buffer-reuse branch August 24, 2026 13:32
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