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.
What
Add an
to_xdr_len(&self) -> usizemethod to theWriteXdrtrait 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 ine2e_invoke.rsallocates aVec<u8>per ledger entry just to getbuf.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.