Skip to content

CEP-0036: Box Dyn Small-Object Optimization

Draft

Draft proposal for small-object optimization in Box(dyn C). V1 Box(dyn C) has no public layout guarantee and may assume heap-owned payload storage.

Summary

Catalyst should eventually decide whether Box(dyn C) or related erased owner types can store small payloads inline.

V1 Box(dyn C) is the canonical owned dynamic value, but it does not expose layout or promise small-object optimization.

Example

Source code might not change:

const action = box_dyn(Command, PrintCommand { text: "ok" }, allocator)

The proposal is about whether a small payload such as PrintCommand may be stored inline inside the erased owner instead of requiring a separate heap allocation.

Motivation

Small-object optimization can reduce allocations for tiny dynamic payloads. It also complicates pointer stability, ownership, disposal metadata, allocator state, and ABI expectations.

Proposed Direction

The proposal should cover:

  • whether SOO belongs in Box(dyn C) or a separate owner type;
  • payload size/alignment thresholds;
  • pointer stability through moves and upcasts;
  • disposal and allocator behavior for inline payloads;
  • interaction with public dyn ABI and downcasting.

V1 Compatibility

V1 does not require or expose small-object optimization. Box(dyn C) users cannot depend on layout or inline storage.