Repository navigation
perf(generator): keyed, version-tolerant and nested bodies take the item chain - #450
Merged
Merged
Conversation
…ement (#355) NinoValueItem and NinoSlotItem read NinoKind<T, TFormatter>.Stride, a static readonly field, in MaxSize, WriteAt and ReadAt of every element (#436): it folds only where Tier1 compiles the loop after the class is initialized, not at FullOpts, NativeAOT, IL2CPP or Mono. Each item's bytes now come from a constant. A composite's raw item is picked outside the loop as NinoStructItem<T> (Unsafe.SizeOf, raw values being their memory) or NinoBoolItem; NinoValueItem is a block only, sized by its formatter's FixedSize (a literal of a generated formatter). A slot's longest single value is a type argument (INinoSize): the generated accessor's literal (its presence byte and the canonical bytes FlatRules reads from the encoding), or NinoMemorySize<T> in composites, where NinoCursor.Item takes a slot only when Unsafe.SizeOf<T?> bounds its stride. INinoMember and INinoProperty extend INinoSize. The bytes are unchanged.
…tem chain (#355) Step C of the unified storage layer: a version-tolerant or keyed body, and a flat body nested in another, now take the one chain of items for their runs, as leaves of that chain rather than loops of their own. The bytes are unchanged. Nino.Core gains the leaves: - NinoRegionItem: the length-prefixed region. A read gets the region's bytes only and skips what a newer version appended; a region longer than the data, or one holding deferred bodies (bit 31), leaves the element to its formatter. - NinoTolerantItem: a member past the region's end keeps its value. - NinoKeyItem (the key from the accessor's INinoKey literal, the value's length written after it) inside NinoEntriesItem (the entries must fill the region): an entry in another order, under a former name or unknown leaves the element. - A nested flat body is one item: NinoFlat.Sealed / Typed for a class (presence or type id, the object made or reused), NinoFlatValues.Item for a struct. An item that may leave says so as a constant (INinoItem.Leaves), and a node stops after it. Without the stop, the items after a leaving one read at source + (uint)int.MinValue with the bytes left wrapped negative, which passes every unsigned length check; the hostile twins in FlatTests.Bodies caught it. With a test after every item, a positional flat struct's runs read in 1.08 times their time, so the test exists only after an item that may leave, and a chain no element leaves keeps the string kernels' loops (no stop, no index). A property of a class type keeps its local copy as NinoReference: with a class as NinoPropertyAt's TValue the whole chain and the kernels over it became code shared over __Canon (a version-tolerant class with one string property wrote its runs in 4.2 times the generated body's time). The generator (FlatRules, FlatEmitter, TypeFacts.Flat) admits positional, version-tolerant and keyed bodies and members of another generated type whose body is flat (memoized per compilation, cycles not flat), counts levels against the JIT's inline depth and passes the class bodies one element opens, so a run nested near NinoDepth.Inline goes element by element. Bodies that are not positional, structs, generic types and bodies nesting a class keep their member-by-member bodies and take the chain for runs only. Tests: byte twins for keyed, version-tolerant, nested and struct bodies (runs of 1 to 600, lists, reads into existing elements, every cut rejected), reads across versions, a run nested past the inline depth, a dictionary with a free entry, hostile bytes read alike by the flat and the generated reads (every byte changed, lengths and keys set to 0, -1, the sign bit, too long), a ShapeMatrixTests dimension (a flat body nesting two in every format), and fuzz inputs (keyed, version-tolerant and nested bodies in the Flat targets). Refs #355
runtime.md and generator.md describe step C of the unified storage layer: the leaves version-tolerant and keyed bodies take on the one chain of items (the region, a tolerant member, a keyed entry), a flat body nested as one item, INinoItem.Leaves and the stop after a leaving item, NinoReference for a property of a class type, and which bodies take the chain for their runs only. Refs #355
…355) Done: a flat struct whose chain never leaves the element (positional, no class nested) takes the string kernels' loops again, picked in NinoFlatValues' hooks; the element items of classes test the body's size before storing a new object only when the body may leave. In NinoFlatRuns' driver the branch made the class driver too large to inline into NinoFlat.ReadSealed at TC=0 (asm.py: "too many il bytes", a call more per run). IncrementalGeneratorTests expects NinoReference for a string property. Measured (local, alternated, against 047e0e0): ManagedStructs write 0.98 / read 0.96 at Tier1, a flat struct's run read 0.96, OrderBooks read 0.93 at Tier1 (1.08 at TC=0 before this change, being re-measured). Left: re-measure OrderBooks at TC=0 and re-dump the listings; measure the new leaves at 1, 3 and 1000 elements against main 9540e0b; the full gate. Refs #355
optimize: item sizes from constants (838cf84), and five rules for keyed, version-tolerant and nested flat bodies (Leaves and the stop after a leaving item, NinoReference for a class-typed property, the string kernels' loops for chains no element leaves picked in the hooks, nesting within the inline depth, timing generated types through intercepted calls), with local numbers. audit-generated-code and audit-security carry checks pointing to them. Left: numbers at 1, 3 and 1000 elements against main once measured. Refs #355
…ent (#355) Done: a flat struct's run under NinoFlatRuns.MinRun (16) is written and read element by element, as a flat class's already was. Against main 9540e0b (local, alternated, Tier1) the kernels' fixed cost made a run of one flat struct write in 2.1 times main's time (a version-tolerant struct 2.8), of three 1.35 (2.1); main writes these elements one at a time. Measured against main at 1000 elements (Tier1): flat struct write 0.68 / read 0.76, version-tolerant class write 0.87 / read 0.99, version-tolerant struct 0.62 / 0.93, keyed class write 0.80 / read 1.13 (being looked at), nested class 1.00 / 0.98, generic class 0.61 / 0.89. Left: re-measure 1 and 3 elements with this change; keyed reads of long runs; the full gate. Refs #355
…at a time (#355) Done: the gate for flat struct runs under NinoFlatRuns.MinRun moved from the kernels' entry (WriteStrings, ReadFlatValues) to the branch in NinoRuns' Write and Read (ShortFlatValues), so a short run takes the inline loops of values as on main, not two out-of-line calls and then a loop one at a time. With the gate in the entry a run of one flat struct still wrote in 1.55 times main's time, of one version-tolerant struct 1.78 (Tier1, local, alternated). Measured against main 9540e0b at 1000 elements (Tier1, local): flat struct write 0.69 / read 0.77, version-tolerant class 0.80 / 0.87, version-tolerant struct 0.63 / 0.90, keyed class 0.77 / 1.00, nested class 0.82 / 0.88, generic class 0.62 / 0.95. Left: re-measure 1 and 3 elements with this change; the full gate. Refs #355
Nino.Core's public seam gained INinoItem.Leaves, NinoRegionItem, NinoEntriesItem, NinoKeyItem, NinoTolerantItem, INinoKey, NinoReference and the nested NinoFlat.Sealed / Typed and NinoFlatValues.Item items; the generator emits them. UnityPackageDllTests checks the DLLs against the sources. Refs #355
#355) optimize: rule (6), a flat struct's run under MinRun takes the loops of values one at a time, decided at the branch in NinoRuns (2.1 times main's time for a run of one through the kernels, 1.55 with the gate in the kernels' entry, on par at the branch), and every new leaf measured at 1, 3 and 1000 elements against main. Refs #355
4 tasks
1 of 8 tasks
JasonXuDeveloper
added a commit
that referenced
this pull request
Nov 22, 2026
…sses' type id in the typed kernels The flat hooks (INinoFormatter.WriteFlat/ReadFlat, the generated hooks, NinoFlat.WriteSealed/WriteTyped/ ReadSealed/ReadTyped) take the run by in and the writer or reader by ref, and NinoFlatRuns.WriteRun/ReadRun are inlined into them on that writer or reader: the run and the writer were copied by value at each level, a store-forwarding stall per copy. With the entry that cheap, NinoFlatRuns.MinRun (16) is gone: a List<Image> of 1, 3, 16 and 32 wrote in 1.05, 1.02, 0.90 and 0.95 times the time element by element and read in 1.04, 0.99, 0.94 and 0.95 (local x64, alternated; before, with MinRun 1, 1.79 and 1.37 at one element). Short runs reaching the kernels exposed a bug already on feat/storage-layer: a non-sealed flat class nested in a generic class wrote type id 0 (null's id) per element in the typed kernels, its layout printing the model's id instead of the formatter's s_typeId, so a null element read back as a body (ShapeMatrix row 10; at 20 elements on 352c076 too). FormatterEmitter.TypeIdValue is now the one expression both use; FlatTests covers it. Measured so far: see the previous WIP commits. Left: merge feat/storage-layer (#450), asm.py compare against main, the remaining single-class gap, the gate, the docs(skills) commit.
JasonXuDeveloper
added a commit
that referenced
this pull request
Nov 22, 2026
Step C's chain leaves and depth-aware flat hooks, with this branch's run by in and writer or reader by ref through them (WriteFlat/ReadFlat, NinoFlat's drivers, NinoFlatRuns.WriteRun/ReadRun, NinoItems). MinRun stays for a flat struct's runs only (ShortFlatValues, measured on step C's by-value entry); a class's runs take the kernels at every length. Unity DLLs rebuilt by the gate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is step C of #355. Version-tolerant bodies, keyed bodies, and flat bodies nested in another now take the one item chain for their runs. They do it as leaves on that chain, never as loops of their own. The bytes on the wire do not change.
The new leaves (Nino.Core, CompilerServices)
NinoRegionItem<TBody>: an int32 length, then the body.NinoTolerantItem<TItem>: if the region runs out, the member reads 0 bytes and keeps its value. A member cut off halfway is an error.NinoKeyItem<TKey, TItem>insideNinoEntriesItem<TBody>: the key, which comes from the accessor'sINinoKeyliteral, then the length, then the value.NinoFlat<,>.Sealed/.Typed(presence byte or type id). A struct usesNinoFlatValues<>.Item.NinoDepth.Inlinego element by element.NinoReferenceholds the local copy of a class-typed property. Withstringas a type argument, the whole chain and its kernels became code shared over__Canon, and a version-tolerant class wrote in 4.2× its twin's time.A memory-safety bug caught by the hostile twin tests, fixed here
An item that hands its element back returns
int.MinValue. The next node then receivedsource + 2 GBand a wrapped negativeavailable, which passed the unsigned length checks. A raw item after the hand-back would have read out of bounds.Each item now declares a constant,
INinoItem.Leaves, and nodes stop right after an item that may hand its element back. For chains that never do, the check folds away.Also in this PR
static readonlyread per element (Keep hot paths fast where the JIT does not fold: NativeAOT, IL2CPP, Mono and FullOpts #436): the formatter'sFixedSizeliteral,Unsafe.SizeOf, or anINinoSizetype argument. At TC=0, NullableFields' MaxSize folds to the literal 74.NinoFlatRuns, the branch made the class driver too large to inline at TC=0 ("too many il bytes").NinoRunsbranch, not inside the kernels. Before this, a run of one flat struct wrote in 2.1× main's time.CORINFO_HELP_BOXin any optimized method of the head listings.Generated code
Keyed type (
FlatKeyed):Nested type (
FlatOuter), with depth literal 2:Tests
Measured locally (guidance only)
Against main 9540e0b, at 1,000 elements, Tier1:
Verify
--verify, benchmark--verifyandtools/agents.sh --checkpass.Five commits have subjects that start with
WIP:; they were pushed under the work-in-progress rule. Each one builds, and the work is now complete.Not in this step
BadgeCount. Allowing them would makeShallowUserflat.UnmanagedNullableFormatter'sNinoLayout<T>statics at TC=0. They cost a rawT?slot extra and account for the version-tolerant read's 1.11 at TC=0.Part of #355.
Generated by Claude Code