Skip to content

StreamID unnecessarily allocates #135

@piodul

Description

@piodul

The StreamID struct is defined like this:

/// A struct representing a stream ID.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct StreamID {
    pub(crate) id: Vec<u8>,
}

The vector is unnecessary - in the current format, CDC stream IDs are always constant size and have 128 bits. Keeping it as a vector is wasteful, especially that the StreamID struct is embedded within the CDCRow objects which can be created by the library in large quantities.

Proposal: change it to:

pub struct StreamID {
	pub(crate) repr: StreamIDRepr,
}

enum StreamIDRepr {
	StandardSize([u8; 16]),
	NonStandardSize(Vec<u8>),
}

Thanks to the null pointer optimization, the new struct should have the same size as the old one. We are not reducing generality while optimizing the case that will practically happen 100% of the time.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions