Skip to content

perf: Directly serialize signed bytes into Vec holding domain separator#10351

Queued
eichhorl wants to merge 4 commits into
masterfrom
eichhorl/write-signed-byte
Queued

perf: Directly serialize signed bytes into Vec holding domain separator#10351
eichhorl wants to merge 4 commits into
masterfrom
eichhorl/write-signed-byte

Conversation

@eichhorl
Copy link
Copy Markdown
Contributor

@eichhorl eichhorl commented May 29, 2026

Currently there are two kinds of messages that are signed by the replica:

  1. Structured data which is serialized on the fly (e.g. consensus artifacts via serde_cbor, or protobuf).
  2. Data that is already present as raw bytes (e.g. message IDs).

In both cases, the function as_signed_bytes_without_domain_separator currently produces a newly owned vec (a fresh serialization for 1. and a clone for 2.), which is then appended onto a different vector holding the domain prefix.

Instead, this PR replaces fn as_signed_bytes_without_domain_separator(&self) -> Vec<u8> with fn write_signed_bytes_without_domain_separator(&self, bytes: &mut Vec<u8>) which appends/serializes the message bytes directly into the buffer that already holds the domain separator. This saves one clone/allocation of the data to be signed/verified in both cases.

Additionally we remove a few other unnecessary allocations.

@github-actions github-actions Bot added the perf label May 29, 2026
@eichhorl eichhorl changed the title perf: write signed bytes perf: Directly serialize signed bytes into Vec holding domain separator Jun 1, 2026
@eichhorl eichhorl marked this pull request as ready for review June 1, 2026 07:00
@eichhorl eichhorl requested a review from a team as a code owner June 1, 2026 07:00
Copy link
Copy Markdown
Contributor

@alin-at-dfinity alin-at-dfinity left a comment

Choose a reason for hiding this comment

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

Very nice, thank you!

Comment thread rs/types/types/src/messages/webauthn.rs
@eichhorl eichhorl added this pull request to the merge queue Jun 1, 2026
Any commits made after this event will not be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants