Skip to content

Add WriteXdr::to_xdr_len() for zero-allocation size computation #507

Description

@tomerweller

What

Add an to_xdr_len(&self) -> usize method to the WriteXdr trait that computes the serialized XDR byte length without allocating memory or performing I/O.

Why

Several downstream consumers serialize XDR values only to measure their byte length, then discard the bytes. For example, soroban-env-host's rent computation in e2e_invoke.rs allocates a Vec<u8> per ledger entry just to get buf.len(). For a typical Soroban transaction with ~10 footprint entries this results in ~40 unnecessary allocations per transaction in the ledger close hot path.

A dedicated to_xdr_len() method would allow callers to get the serialized size using only arithmetic over in-memory values — no allocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions