Skip to content

Reduce size of Vec to 24 #9706

@overlookmotel

Description

@overlookmotel

Vec is currently 32 bytes. It consists of 4 x 8-bytes fields:

  • Pointer to Vec's contents (NonNull<u8>)
  • Length (usize)
  • Capacity (usize)
  • Pointer to allocator (*const Allocator)

Reduce to 24 bytes

Make length and capacity fields u32.

This is pretty easy.

Reduce to 16 bytes

If arena allocator always created chunks aligned on 4 GiB boundaries, and stored chunk metadata in a header at start of chunks, the pointer field could do double-duty.

Pointer field would be a pointer to the Vec's contents. But also if you zero out the bottom 32 bits it would give you a pointer to the chunk metadata. The chunk metadata would contain a pointer back to the Allocator, with which you can grow/reallocate the Vec etc.

This would require replacing bumpalo with a custom allocator.

Metadata

Metadata

Assignees

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