Skip to content

relay: from_frame allocates a String on every inbound frame's limiter path #1385

Todo

Description

@chappie-daemon

Found by job 050's approver at c6969d3e (PR #1381), where the performance lens was stood down with a reason that turned out to be wrong ("the per-frame work is a 32-byte prefix scan with no allocation").

MessageClass::from_frame (crates/nostream-relay/src/limits.rs:104-111) builds a String for every classified frame — an upper-cased copy of a ≤8-byte word — on the path every inbound frame takes before messages::decode.

Acceptance: the frame's class is derived without allocating (eq_ignore_ascii_case against the eight tokens, or a match on [u8]), with the existing parser cases unchanged and one case added for a frame whose prefix is not ASCII. The measured effect stated: one allocation per inbound frame removed; a before/after count from the existing relay socket harness is enough, no new bench.


For whoever picks this up

  • What is wrong: MessageClass::from_frame copies the quoted leading word of every inbound text frame into a heap String (String::new plus push) just to compare it with eight known message names, so each frame that reaches a quoted word pays one allocation before the message is decoded or handled.
  • Done looks like: the class is derived from a stack buffer or with eq_ignore_ascii_case and from_frame performs no heap allocation, while the_message_class_is_read_from_the_frame_prefix in crates/nostream-relay/tests/limits.rs keeps every existing case and gains one non-ASCII prefix case (["RÉQ"] is Other). The crate has no allocation-counting harness today, so the observing test is new: crates/nostream-relay/tests/frame_alloc.rs, its own test binary with a counting #[global_allocator], whose from_frame_does_not_allocate asserts the count is unchanged across MessageClass::from_frame for all eight class tokens plus an Other frame; it fails before the fix with one allocation per call.
  • Where it lives: crates/nostream-relay/src/limits.rs, MessageClass::from_frame, called for every inbound text frame from Relay::on_client_message in crates/nostream-relay/src/relay.rs.
  • Intent: [Rewrite P6] Hardening: fuzz, benchmark gate, 72h soak, security review #868 explains why the cost matters: its six-lens review and benchmark gate measure the relay before cutover, and this is a per-frame cost on the path every inbound message takes.

Activity

  1. added
    bug
    rewrite
    rust
    factory
    on Dec 4, 2026
  2. self-assigned this
    on Dec 5, 2026
  3. chappie-daemon commented on Dec 6, 2026

    @chappie-daemon
    CollaboratorAuthor

    Delivery date: Friday 2026-12-18.

    A PR that is green and ready for review by then keeps this row yours. If nothing is up by Monday 2026-12-21 we take the row back into our own queue, because the v4 cutover on 2026-12-31 cannot wait on it.

    Your PR #1395 is already up, approved and clean, so this is a checkpoint rather than a start.

    If that date does not work, say so here and we will set one — a stated date is only useful if it is one you can meet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfactoryrewriterust

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions