Skip to content

Box large LoopbackEvent variants to reduce enum size #1737

@bug-ops

Description

@bug-ops

Problem

LoopbackEvent in crates/zeph-core/src/channel.rs has variants with inline data:

  • ToolStart — 5 fields (String, String, Option, Option, Instant)
  • ToolOutput — 11 fields including String, Option, Option<Vec>, etc.

Every LoopbackEvent value is sized to the largest variant (ToolOutput), which is likely 200+ bytes. Since these events flow through an mpsc channel, every smaller variant (Chunk, Flush, Status) carries this overhead.

Proposed Changes

  1. Extract ToolStartData (owned) and ToolOutputData (owned) structs
  2. Box them in the enum: ToolStart(Box<ToolStartData>), ToolOutput(Box<ToolOutputData>)
  3. This reduces the base enum size to ~40 bytes (largest non-boxed variant)

Motivation

  • Reduces memory pressure on the mpsc channel buffer
  • Simplifies match arms (destructure the struct, not 11 inline fields)
  • Existing borrowed ToolStartEvent<'a> / ToolOutputEvent<'a> structs already model the same shape

Files

  • crates/zeph-core/src/channel.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    archArchitecture and designenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions