Skip to content

Perf: move cold Object state into sidecars to reach the 512-byte slab #86

Description

@chrisbbreuer

Evidence

The current Debug DWARF layout reports value.Object at 640 bytes. zig-gc adds a 48-byte header, so every ordinary object is a 688-byte cell and lands in GcCellBacking's 1024-byte size class. Reaching the existing 512-byte class requires Object at or below 464 bytes: at least 176 payload bytes must move or overlap.

The post-#85 ReleaseFast object_churn profile confirms the structural cost:

  • platform memmove / default Object initialization: 254 sampled leaves
  • nursery sweep: 386
  • GcCellBacking.freeFn: 164
  • GcCellBacking.allocFn: 67
  • Binding.finalize: 80

Prior #78/#79 proved that merely changing or adding a non-power-of-two bucket regresses. The next viable direction is an actual payload reduction.

Parent: #62

Proposed design constraints

  • Keep hot ordinary-object fields inline: shape, slots, four inline values, prototype, dense elements/length, ownership/barrier state, backing allocator, and the property/element locks.
  • Move or overlap cold mutually exclusive exotic state: BigInt text/value, Symbol metadata, RegExp metadata, Temporal/typed-array/DataView/ArrayBuffer payloads, weak/finalization collection storage, module namespace data, and other variant-only records.
  • Prefer compact untagged payload unions where existing object-kind flags already prove exclusivity; use lazily allocated GC-owned sidecars only where states can coexist.
  • Trace and finalize every moved edge/store precisely, account sidecar bytes under heap limits, and retain no compatibility padding.
  • Add a compile-time size gate proving zig-gc cellAllocationBytes(Object) is at most 512.

Acceptance criteria

  • Object cells select the existing 512-byte bucket; no new size class.
  • Full units, TSan publication shards, test262-parallel, and benchmark harness remain green with zero leaks.
  • object_churn order-balanced A/B shows a material repeatable win with exact checksum.
  • Recheck arrays, properties, calls, polymorphic properties, context lifecycle, and shared scaling to reject any sidecar or indirection regression.
  • Land as small reviewable issue-linked commits, splitting payload representation, tracing/finalization, and benchmark evidence where practical.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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