Skip to content

Make every fixed-size formatter a block formatter, and let blocks compose #348

Open

Description

@JasonXuDeveloper

Found in an audit of main (07972d7) for hand-enumerated fast paths and dispatch that is not devirtualized. The rule: one generic or structural path, specialized by the compiler, never a hand-written list of types, sizes or key kinds; a capability is reached by a constrained call on the formatter's struct type parameter, never an interface cast. Gain figures are estimates until a runner A/B.

F4 (C) Block formatters do not compose: KeyValuePair, ValueTuple, DateTimeOffset

  • KeyValuePairFormatter.cs:18-58 and TupleFormatters.g.cs (tools/CodeGen): FixedSize/BlockMap only when every
    item is raw; NinoBlockMap.Block<TItem, TFormatter> (NinoBlockMap.cs:58-72) already merges a nested block's
    map (generated structs use it). So (int, DateTimeOffset), KeyValuePair<int, MyBlockStruct>, a pair holding a
    [NinoType] struct with a bool or a nested fixed struct, (Guid, (int, bool)) are written element by element.

  • DateTimeOffsetFormatter (PrimitiveFormatters.cs:58-130) is no INinoBlockFormatter; instead NinoElements
    names it in four places (:284-285 ReadOverwrites, :396 BlockStride, :460-462 WriteBlock, :528-534 Read).
    Because it is not a block, nothing containing a DateTimeOffset (a tuple, a pair, a dictionary value through
    NinoBlockPlan, PriorityQueueHeap.TryWrite) is a block either.

  • Fix: DateTimeOffsetFormatter implements INinoBlockFormatter<DateTimeOffset> (FixedSize 10, WriteFixed/ReadBlock =
    its Write/Read, BlockMap null or the probed ticks/offset runs), and the four typeof(DateTimeOffsetFormatter) tests
    go. Pair and tuple formatters: an item is raw or a block (NinoBlockPlan<Ti,TFi>.Size > 0), FixedSize the sum,
    BlockMap through .Block<Ti,TFi>, WriteFixed/ReadBlock through NinoBlocks.WriteFixed/ReadBlock (constrained
    calls). Route every collection of T? and NinoNullable<T> through the shared block element path #295 (T? and NinoNullable as a "fourth kind" in NinoElements) is the same move for slots: once every
    fixed-size formatter is a block formatter, NinoElements has one kind, not four.

  • Gain: one reservation per collection instead of one per element, plus the vector block paths where a map exists;
    Rust's equivalent change (FIXED_SIZE for derived structs) measured 61-91 % faster (blocks.md). Estimate 1.5-3x for
    List<(int, DateTimeOffset)>-like cases.

  • Risk: bytes identical by construction (golden/conformance tests prove it); Untrusted checks of nested items must
    reach NinoBlockMap.Checked; netstandard per-element interface call (F2) until F2 lands.

  • DateTimeOffsetFormatter as INinoBlockFormatter; the four typeof(DateTimeOffsetFormatter) tests removed

  • KeyValuePairFormatter and the CodeGen tuple formatters: items raw or block, NinoBlockMap.Block

  • golden bytes and conformance unchanged; Untrusted checks of nested items

  • A/B: lists/arrays/dictionary values of (int, DateTimeOffset), KeyValuePair<int, BlockStruct>

Sibling of #295 (the T? and NinoNullable part of the same rule).


Generated by Claude Code

Activity

  1. added
    kind: perf
    kind: refactor
    area: core
    on Nov 16, 2026
  2. added this to the v4.0.0 milestone on Nov 16, 2026
  3. JasonXuDeveloper commented on Nov 18, 2026

    @JasonXuDeveloper
    OwnerAuthor

    This issue is now part of #355's single mechanism; see the rules at the top of #355's body and this comment.

    One composition rule. Composite elements, meaning KeyValuePair, ValueTuple/Tuple of any arity, and generic [NinoType] structs and classes, derive their kind from their members once per closed type:

    • raw: every member is raw and this runtime's layout equals the wire layout, according to the existing layout check, never unmanaged;
    • composed block: every member has a fixed size, so the block map is built from the members' maps;
    • otherwise: each member takes its own path.

    What follows from it:


    Generated by Claude Code

  4. JasonXuDeveloper commented on Nov 18, 2026

    @JasonXuDeveloper
    OwnerAuthor

    This landed on feat/storage-layer in #408 (merge 79bfcac). CI was green, including Unity 2022.3, 6000.6 and WebGL.

    What changed

    • Composites compose their block from their items. NinoBlockMap.Item and NinoBlocks.ItemSize/WriteItem/ReadItem put the composition in one place. "Raw" is decided by the layout check, not by unmanaged.
    • Composite formatters follow one pattern. This covers KeyValuePair, every tuple including the 8-item ValueTuple, and the generator's generic structs. Composites such as (int, DateTimeOffset), KeyValuePair<int, BlockStruct> and generic [NinoType] structs with fixed-size members are now blocks.
    • DateTimeOffset is now a block formatter. Its own loops and the typeof tests are gone.
    • The bytes are unchanged. RuntimeTests and the Unity layout tests check that the CoreCLR bytes are written for tuples and pairs whose memory layout differs from runtime to runtime.

    Still open

    • One generic entry block for sets and dictionaries. This needs PR 3's entry layouts.
    • The top-level fixed path for generic fixed structs.

    Both are tracked in #355. This issue closes with the pull request that takes feat/storage-layer to main.


    Generated by Claude Code

  5. JasonXuDeveloper commented on Nov 18, 2026

    @JasonXuDeveloper
    OwnerAuthor

    Progress from #409 (merged into feat/storage-layer, part of #355): this issue's writes now go through Core's run cursor and one write loop per element kind. The dispatch chain is emitted inside Core's skeleton as one non-generic WriteRun, and the per-container WriteElements/WritePairs* entry points are removed. The bytes are unchanged. Reads follow in the next step. The issue closes with the final feat/storage-layer → main PR and its runner A/B.


    Generated by Claude Code

  6. JasonXuDeveloper commented on Nov 20, 2026

    @JasonXuDeveloper
    OwnerAuthor

    #432 (26a37c4) checked the storage side of this issue on feat/storage-layer and found nothing left: the checklist was finished from #408 onward.

    Still open:


    Generated by Claude Code

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

    area: corekind: perfkind: refactor

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions