Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .claude/skills/benchmark/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ runs in both, so its two results show how much the machine moved. Heavy runs go
- **Reach the commits** with `git merge -s ours --no-edit <ref>` (history only: the test branch keeps main's code,
so its CI runs main's code; merging an experiment's code ran CI on it, and a Go test that overflowed `int` on 386
and a Windows stack test mailed the owner a failure per push).
Check `git merge-base --is-ancestor <sha> HEAD` for both refs after the history merges. The #353 benchmark
baseline and candidate were built on independent branches, so merging only the candidate left the baseline
missing from every runner checkout (44333395182).
- **Time the Nino.Core build you mean.** BenchmarkDotNet's runner project (`Nino.Benchmark-<job>`) gets Nino.Core
only through Nino.Benchmark's references, so a referenced package built for fewer frameworks than Nino.Core brings
an older build into it: until f01a8d3c Nino.Immutable (net8.0 only) made every runner process load Nino.Core's
Expand Down
11 changes: 11 additions & 0 deletions .claude/skills/optimize-runtimes/references/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ value check in a runtime or a template.

## Checking blocks in Go

- Reserve one checked block for fixed-width Go containers. Use constant wire offsets for padded primitive pairs
and copy compatible primitive grids as blocks. In runtime A/B
[44339615693](https://github.com/JasonXuDeveloper/Nino/actions/runs/44339615693), padded-pair read times fell
66–75 % on the measured x64 CPUs and 72 % on Neoverse-N2. Byte-grid writes fell 92–96 % on both architectures.
Fixed DateTimeOffset sequence writes fell 52–59 % on x64 and 47 % on Neoverse-N2.
- Encode fixed map entries through their addresses. In the original fixed-stride loop the x64 GUID entry value
crossed two stack temporaries. The address loop reduced ten `MOVUPS` per entry to two, with the stride guard
intact. In [44347813411](https://github.com/JasonXuDeveloper/Nino/actions/runs/44347813411) the revised GUID map
write took 82–85 % less time on x64 and 81 % less on Neoverse-N2. The revised map read took 52–54 % less on
x64 and 45 % less on Neoverse-N2.

- Check a block of range-limited 8- or 16-byte values four a step with one compare each (`w[0].Valid() && ... &&
w[3].Valid()`, then the failing step value by value), each `Valid` a single compare (a signed range from 0 as
unsigned; a Decimal's flags without the sign, rotated by 16 bits, `<= 28`). Writing 1000 values (runtime A/B runs
Expand Down
10 changes: 10 additions & 0 deletions .claude/skills/optimize-runtimes/references/dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ call, a helper that takes a function, or a `read_into` / `deserializeInto` path.
the template's had none): in the release build of `tests/generated` the standalone raw `read`/`write` symbols are
gone and their callers inline them (no runner number yet: the benches' `Point` uses the macros since).

- Generate a direct fixed-stride fallback when `TryReadRaw` or `TryWriteRaw` declines a Go layout. Apple Arm64
disassembly of the padded Gappy and Marked fixtures had direct decode and encode calls on the fallback.
Keep the exported callback helpers available for callers that supply their own codecs.
- Keep structural composite-key discovery outside Go's scalar and string duplicate loops. When the initial #353
implementation sent all keys through the shared cache and added a byte-size test to the string loop,
[44339615693](https://github.com/JasonXuDeveloper/Nino/actions/runs/44339615693) measured the eight-int control
15 % higher on Neoverse-N2. Caching only the composite field walk and restoring the string probe brought both
controls within 2 % by median on that CPU ([44347813411](https://github.com/JasonXuDeveloper/Nino/actions/runs/44347813411)).
The bytewise path still uses the reader's shared seeded table and bounded probing.

## Reuse branches

- Keep reuse branches off the read path of a new value: share the body, not the dispatch. Reading into an existing
Expand Down
5 changes: 5 additions & 0 deletions .claude/skills/platforms/references/emulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ crashing. Read it before running anything under qemu or taking a listing for Arm
8 runs with qemu 8.2 and the runners' qemu, and main's code before the run that showed it (f618b973) crashed too
(1 of 10, more allocation only made it likelier); Go 1.24 crashed in 0 of 8, `GOMAXPROCS=1` in 0 of 18, `GOARM=6`
did not help (4 of 8). runtimes.yml sets it on that step (r101).
Use QEMU user-mode 10.0.13 or later for local Go 386 tests on Arm64 Linux. Go 1.26.11's same static
test binary reported `bad g in signal handler` or `morestack on gsignal` on QEMU 7.2.22. On Debian
trixie's QEMU 10.0.13 it passed three runs and `GOARCH=386 go test -exec qemu-i386 ./...` passed with
asynchronous preemption enabled (#353). Where QEMU 7.2 is required, `GODEBUG=asyncpreemptoff=1` and
`GOMAXPROCS=1` allowed the 386, Arm32 and s390x suites to pass.
- To run tests under qemu-aarch64, pass `-cpu neoverse-n1` (listings can keep the default): qemu 8.2's default CPU
(`max`) has LRCPC2, whose `ldapur`/`stlur` (what the optimizing JIT emits for `Volatile.Read`/`Write` of a field) it
emulates wrong. With or without Nino's code, runs crashed (`ToImmutableDictionary`), or a static field written by
Expand Down
16 changes: 14 additions & 2 deletions runtimes/csharp/src/Nino.Codegen/Targets/Go/GoShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public sealed class GoShape
/// <summary>Whether arrays of it are one block (<c>nino.ReadPrimitives</c>).</summary>
public bool Block { get; internal set; }

/// <summary>Whether sequences of this value use nino.ReadBlock and nino.WriteBlock.</summary>
public bool BlockValue { get; internal set; }

/// <summary>Whether this value needs range validation when written outside raw memory.</summary>
public bool CheckedWrite { get; internal set; }

/// <summary>Whether the fixed encoder omits padding, unused slots or false booleans.</summary>
public bool NeedsZero => Kind is "rawstruct" or "emptystruct" or "rawnullable" or "rawtuple" || Primitive == "Bool";

/// <summary>Whether the key of each pair is checked for repeats.</summary>
public bool UniqueKeys { get; internal set; }

/// <summary>A raw struct that can be copied as memory, its arrays as one block; else null.</summary>
public GoRawBlock? RawBlock { get; internal set; }

Expand Down Expand Up @@ -92,7 +104,7 @@ public sealed class GoShape
/// <c>fixed</c> (raw values at their stride),
/// <c>unique</c> (a set of comparable values), <c>stringset</c>, <c>slice</c>; a map's: <c>block</c>
/// (primitive keys and values, pairs copied as one block where their memory is their bytes; repeated keys
/// fail), <c>unique</c> (repeated keys fail) or <c>entries</c>.
/// fail), <c>fixed</c> (both shapes have a stride), <c>unique</c> (repeated keys fail) or <c>entries</c>.
/// </summary>
public string? Mode { get; internal set; }

Expand Down Expand Up @@ -141,7 +153,7 @@ private IEnumerable<string> Parts()
yield return Struct?.FullName ?? "";
yield return Type?.FullName ?? "";
yield return Named?.FullName ?? "";
yield return (Mode ?? "") + (UniqueSlots ? "/unique" : "");
yield return (Mode ?? "") + (UniqueSlots || UniqueKeys ? "/unique" : "");
yield return Pair ? "pair" : "";
yield return FlagOffset + "/" + ValueOffset + "/" + Rank + (Clean ? "/clean" : "") + (SlotElement ? "/slot" : "");
yield return string.Join("/", Offsets);
Expand Down
17 changes: 10 additions & 7 deletions runtimes/csharp/src/Nino.Codegen/Targets/Go/GoTarget.Shapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ internal GoShape Shape(ValueModel value, bool key)
bool set = value.Collection is CollectionKind.HashSet or CollectionKind.SortedSet ||
CodegenModel.Implements(value.Clr, "System.Collections.Generic.ISet`1") != null;
string mode =
element.Kind == "prim" && element.Primitive == "U8" ? "bytes"
: set && Comparable(element) ? "unique"
set && Comparable(element) ? "unique"
: element.Kind == "prim" && element.Primitive == "U8" ? "bytes"
: set && element.Kind is "string" or "utf8" ? "stringset"
: element.Kind == "prim" && element.Primitive == "Bool" ? "bools"
: element.Block ? "block"
: element.Kind == "prim" && BlockValues.Contains(element.Primitive!) ? "values"
: element.BlockValue ? "values"
: element is { Kind: "rawnullable", Clean: true, Inner.Block: true } ? "ninonullables"
: element is { Kind: "rawnullable", SlotElement: true, Inner.Block: true } ? "nullableslots"
: element.Kind is "rawstruct" or "rawnullable" or "rawtuple" ? "fixed"
: element.Size > 0 && element.Kind != "emptystruct" ? "fixed"
: "slice";
return Open(value, new GoShape("seq")
{
Expand All @@ -106,11 +106,13 @@ internal GoShape Shape(ValueModel value, bool key)
case ValueKind.Map:
{
var (k, v) = (Shape(value.Key!, true), Shape(value.Value!, false));
bool unique = Comparable(k) || k.Kind is "keystring" or "keyutf8";
return Open(value, new GoShape("map")
{
Key = k, Value = v,
Key = k, Value = v, UniqueKeys = unique,
Mode = k.Block && v.Block ? "block"
: Comparable(k) || k.Kind is "keystring" or "keyutf8" ? "unique" : "entries",
: k.Size > 0 && v.Size > 0 ? "fixed"
: unique ? "unique" : "entries",
MinSize = 4,
}, false);
}
Expand All @@ -133,7 +135,7 @@ internal GoShape Shape(ValueModel value, bool key)
case ValueKind.Version:
return new GoShape("version") { MinSize = 4 };
case ValueKind.DateTimeOffset:
return new GoShape("datetimeoffset") { MinSize = 10 };
return new GoShape("datetimeoffset") { MinSize = 10, Size = 10, CheckedWrite = true };
case ValueKind.Unsupported:
throw new UnsupportedException(value.Problem!.Replace("{lang}", "Go"));
default:
Expand Down Expand Up @@ -363,6 +365,7 @@ private GoShape Raw(ValueModel value)
return new GoShape("prim")
{
Primitive = p.Name, Size = value.Size, MinSize = value.Size, Block = p.Block,
BlockValue = BlockValues.Contains(p.Name), CheckedWrite = p.Validated && p.Name != "Bool",
// Read in a run of fixed-size members: any bit pattern is valid.
Runnable = !p.Validated,
};
Expand Down
6 changes: 5 additions & 1 deletion runtimes/csharp/src/Nino.Codegen/Templates/go/shapes.sbn
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func reads_into(s)
if s.kind == "seq"
ret s.mode != "bytes" && s.mode != "block" && s.mode != "bools" && s.mode != "values" && s.mode != "ninonullables" && s.mode != "nullableslots" && s.mode != "unique" && s.mode != "stringset" && s.mode != "fixed"
else if s.kind == "map"
ret s.mode != "block" && s.mode != "unique"
ret s.mode == "entries" || (s.mode == "fixed" && !s.unique_keys)
end
ret false
end
Expand Down Expand Up @@ -311,6 +311,8 @@ func decode(s, o)
ret decode_fn(s) + "(r, " + span(o, s.size) + ")"
when "emptystruct"
ret name(s.struct) + "{}"
when "datetimeoffset"
ret "r.DateTimeOffsetAt(" + span(o, s.size) + ")"
end
$a = at(o)
case s.primitive
Expand Down Expand Up @@ -364,6 +366,8 @@ func encode(s, o, x)
ret [encode_fn(s) + "(" + span(o, s.size) + ", " + x + ")"]
when "emptystruct"
ret []
when "datetimeoffset"
ret [x + ".Put(" + span(o, s.size) + ")"]
end
$a = at(o)
case s.primitive
Expand Down
Loading
Loading