Skip to content

Reduce size of Frame - #69

Open
glbrntt wants to merge 1 commit into
apple:mainfrom
glbrntt:frame-size
Open

Reduce size of Frame#69
glbrntt wants to merge 1 commit into
apple:mainfrom
glbrntt:frame-size

Conversation

@glbrntt

@glbrntt glbrntt commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Frame is large: 161 bytes with a stride of 168 bytes. A reasonably large part of this is just padding which is easily removed by reordering stored properties.

This patch moves properties around to reduce the size and stride down to 136 bytes.

Frame is large: 161 bytes with a stride of 168 bytes. A reasonably large
part of this is just padding which is easily removed by reordering
stored properties.

This patch moves properties around to reduce the size and stride down
to 136 bytes.

@agnosticdev agnosticdev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you George, just one question but otherwise fine!

public var connectionComplete: Bool = false
private var _endOffset: UInt32 = 0
private var _effectiveBufferLength: UInt32 = 0
private var _aggregateBufferLength: UInt32 = 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So because of the out of order arrangement of these properties extra padding was being added, is that what was happening?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the order the properties were in: Swift lays out types in the order they're declared in.

As an example the Buffer enum was stored first and is 33 bytes in size with an 8 byte alignment. It was followed by a NetworkUniqueArray<UInt8> which is 24 bytes (also 8 byte alignment). Because of the alignment there's 7 bytes of padding between the two, instead you can move smaller types (e.g. 7 booleans) into that space that would otherwise be padding.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants