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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ about: Something behaves differently from what is documented

**Versions**
- `MattLorimor.ProbabilisticDataStructures`:
- Target framework (e.g. net10.0):
- Target framework (e.g. net11.0):
- OS:

**Which structure?**
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ jobs:
- name: Check out
uses: actions/checkout@v7

# global.json's SDK, which builds both frameworks, and a .NET 10 SDK beside it
# for the .NET 10 runtime the net10.0 suite runs on. setup-dotnet installs the
# versions from both inputs.
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
global-json-file: global.json

- name: Restore
Expand All @@ -64,10 +68,13 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore -warnaserror

# Runs the suite once per target framework, and fails if either run fails. A
# prefix rather than a file name, because each framework writes its own results
# and a fixed name keeps only whichever finished last.
- name: Test
run: >-
dotnet test --configuration Release --no-build
--logger "trx;LogFileName=test-results.trx"
--logger "trx;LogFilePrefix=test-results"
--results-directory ${{ github.workspace }}/test-results

- name: Upload test results
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ jobs:
# must be present for the version check below.
fetch-depth: 0

# As in CI: global.json's SDK builds both frameworks, and the .NET 10 SDK beside
# it brings the runtime the net10.0 suite runs on.
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
global-json-file: global.json

# A tag that disagrees with VersionPrefix would publish a package whose
Expand Down
3 changes: 3 additions & 0 deletions Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- net10.0 only, until a stable BenchmarkDotNet supports .NET 11. 0.15.8 stops
before running anything on .NET 11 ("GetRuntimeVersion not implemented for
NotRecognized": its runtime list ends at .NET 10); 0.16.0-preview.2 adds it. -->
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<!-- BenchmarkDotNet requires optimized builds; guard against Debug runs. -->
Expand Down
20 changes: 16 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **A build for .NET 11 beside the one for .NET 10.** The package carries `lib/net10.0` and
`lib/net11.0`, built from the same source with the same API, and the suite runs on both
frameworks, each on its own runtime, on every CI runner: Linux and Windows on x64 and
arm64, and macOS on arm64. .NET 10 is an LTS release and .NET 11 an STS one, and both
are supported until 2028-11-14, so neither build is dropped for the other.
<br><br>
Each build depends on the `System.IO.Hashing` released with its own .NET: 10.0.15 for
net10.0, and 11.0.0 for net11.0. An application on .NET 10 keeps a dependency on the
10.0 line, where 6.2.0 had 10.0.11.

- **`ReadOptions`, a memory budget for reading.** Every structure gains
`ReadFrom(Stream, ReadOptions)` and `ReadFrom(Stream, Func<ReadOnlySpan<byte>, ulong>,
ReadOptions)`, and `Persistence.FromByteArray<T>` the same two. The budget is the most
Expand Down Expand Up @@ -752,14 +762,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
by 16 to 440 bytes read as a byte array, measured in a no-GC region; the four kilobytes
of slack the read-budget tests allowed had absorbed all of it. The stream
`FromByteArray` reads through, 64 bytes, and the read's own budget, 48, were charged
nowhere, and a checksum's state was charged as a small object of 64 bytes where it is 24.
nowhere, and a checksum's state was charged as a small object of 64 bytes where it is 24
with System.IO.Hashing 10.
Most readers made objects they did not charge, their structure's own among them; some
made objects only to replace them, and a `MementoFilter` read gathered each run into a
list that grew to the longest run in the table. Now a read is charged the stream and the
budget once, and a read nested in it neither; a checksum's state is charged what it
allocates; and each reader charges each object it makes where it makes it, at its size
measured on a 64-bit runtime or as a small object where that is larger, with its price
pricing the same charge, so the two still come to the same sum. The objects made only to
allocates with the System.IO.Hashing loaded, 24 bytes with 10 and 32 with 11, whose
`Crc32` holds one field more; and each reader charges each object it makes where it
makes it, at its size measured on a 64-bit runtime or as a small object where that is
larger, with its price pricing the same charge, so the two still come to the same sum. The objects made only to
be replaced are no longer made, and a `MementoFilter` run is checked through one view of
the table's slots. A read from a stream is charged the stream it did not make, 64 bytes
past what it allocates, since nothing tells the two reads apart. Measured as a byte
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ProbabilisticDataStructures

Probabilistic data structures for C#. Managed IL throughout — no `unsafe`, no pointers,
no hardware intrinsics — targeting `net10.0` with one dependency, `System.IO.Hashing`.
no hardware intrinsics — targeting `net10.0` and `net11.0` with one dependency, `System.IO.Hashing`.

## Read these before writing anything

Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ MSBuild thinks is up to date, so an incremental `-warnaserror` build can report
on code that will not compile from scratch — which is exactly how a real defect got
through several green checks in a row.

The library and the suite target net10.0 and net11.0. Building takes the .NET 11 SDK that
`global.json` names, and testing takes the .NET 10 runtime as well, since the suite runs
once on each. In a tree last restored for other target frameworks, such as one from before
net11.0 was added, `dotnet clean` fails with NETSDK1005 until a restore has run, and the
`&&` above then skips the build: run `dotnet restore` first.

New structures follow the pattern of the existing ones: a class with the same shape of
API, span overloads beside the array ones, persistence with a golden fixture, an entry
in the README's decision table, a row in its table of how much each one holds and a note
Expand Down
28 changes: 25 additions & 3 deletions ProbabilisticDataStructures/PersistenceFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,10 +1941,32 @@ internal static long NestedEnvelopeCost(ulong length) => ReadBudget.Sum(

/// <summary>
/// What a checksum's state allocates: a <see cref="Crc32"/>, which holds its running
/// value, measured at 24 bytes on a 64-bit runtime. It was charged as a small object
/// of 64, 40 more than it takes (#346).
/// value, measured on a 64-bit runtime at 24 bytes with System.IO.Hashing 10 and 32
/// with 11. It was charged as a small object of 64, 40 more than it takes with 10
/// (#346).
/// </summary>
internal const long ChecksumStateCost = 24;
/// <remarks>
/// The size is the package's, not the runtime's. System.IO.Hashing 11.0.0's
/// <see cref="Crc32"/> adds a field, <c>ParameterSet</c>, beside its running value and
/// its hash length, and one allocates 32 bytes with 11.0.0 and 24 with 10.0.14 and
/// 10.0.15, on .NET 10 and .NET 11 alike: 11.0.0's own net10.0 build on .NET 10 is 32,
/// and 10.0.15 on .NET 11 is 24. Each of this library's target frameworks depends on a
/// different major of the package, but the application decides which one loads, and a
/// .NET 10 application that takes 11.x runs the net10.0 build with the larger state. So
/// the cost is read once from the version of the assembly loaded, not from the
/// framework the library was built for.
/// </remarks>
internal static readonly long ChecksumStateCost =
ChecksumStateCostFor(typeof(Crc32).Assembly.GetName().Version);

/// <summary>
/// What a <see cref="Crc32"/> allocates with the System.IO.Hashing of
/// <paramref name="hashing"/>, its assembly version: 24 bytes before 11 and 32 from 11
/// on (<see cref="ChecksumStateCost"/>). A version that cannot be read is charged the
/// larger, since a read may be charged more than it allocates but never less.
/// </summary>
internal static long ChecksumStateCostFor(Version? hashing) =>
hashing is null || hashing.Major >= 11 ? 32 : 24;

/// <summary>
/// What a read makes once, around everything it reads, whatever it holds, and a read
Expand Down
14 changes: 11 additions & 3 deletions ProbabilisticDataStructures/ProbabilisticDataStructures.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<!-- One build for each supported .NET, and the test project runs the suite on each.
.NET 10 is the LTS and .NET 11 the STS, both supported to the same day. -->
<TargetFrameworks>net10.0;net11.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Enabled for the library only. The annotations ship in the package and give
consumers null analysis against this API; the test and benchmark projects
Expand Down Expand Up @@ -54,8 +56,14 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IO.Hashing" Version="10.0.14" />
<!-- Each build takes the System.IO.Hashing released with its own .NET, so that a
.NET 10 consumer's dependency stays on the 10.0 line it was on before net11.0
was added. The 11.0.0 package would serve both: it carries a net10.0 build too. -->
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="System.IO.Hashing" Version="10.0.15" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net11.0'">
<PackageReference Include="System.IO.Hashing" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ building at the scale it describes, which is the measurement as of commit 426348
dotnet add package MattLorimor.ProbabilisticDataStructures
```

Requires .NET 10 or later. See [CHANGELOG.md](CHANGELOG.md) for what changed in each
Targets .NET 10 and .NET 11. See [CHANGELOG.md](CHANGELOG.md) for what changed in each
release.

The package ID carries a prefix, but the assembly and namespace do not:
Expand Down
29 changes: 22 additions & 7 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ file `--out` gets Stryker's JSON and HTML reports, its log, the tests it ran, an
`summary.txt`: the mutants by verdict, then every Survived, Timeout and NoCoverage one
with its line and mutation. `--jobs` sets how many tests run at once while it finds
them, and options after `--` go to Stryker. The settings are `stryker-config.json`'s;
the script adds the scope and the test filter.
the script adds the scope, the test filter and the framework. A sweep is of one
framework's build, net10.0 unless `--framework` names the other: Stryker picks one at
random for a project that targets several, and every sweep recorded here ran on net10.0.

Scope every run. Stryker is not part of any build, the whole library generates more
than twelve thousand mutants (12,512 at master 7e339df), and the output needs human
Expand Down Expand Up @@ -697,9 +699,14 @@ Stryker mutator does, so they stay as #179 records them, held by probes at scale
the suite; the fourth, `Allocate` without its size check, Stryker does make, and the test
#179 added for it kills it.

`mutate.sh` reports a run whose test host crashed as SURVIVED with no count after it,
where a real survivor reads "SURVIVED (all N passed)". Read that as the crash it is,
which is a detection, and confirm it by running the suite with the mutant in.
`mutate.sh` reads the summary of every target framework, since a mutant can fail one
framework's suite and pass the other's, and the last line is whichever finished last. A
mutant either fails is killed, and the verdict says where: "killed (10 tests on net11.0;
all 131 on net10.0 passed)". A real survivor reads "SURVIVED (all N on net10.0, all N on
net11.0 passed)". A run that failed with no failing summary, from a test host that crashed
or a runtime that is not installed, reads "SURVIVED (no failing summary, but dotnet test
exited N; summaries from: ...)". Read a crash as the detection it is, and confirm it by
running the suite with the mutant in.

**Before 5.0.0, Stryker and this suite's parallelism did not mix.** The test assembly
declares `[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]`, and Stryker
Expand Down Expand Up @@ -912,9 +919,11 @@ rest of a message survives, as it should, and one that deletes the guard does no
room. One that a collection ended is measured again, so measured work must be
repeatable and rebuild what it changes before each attempt, and work that cannot get
a region fails saying so rather than being counted without one. A room must be one
every runner gives: macOS collects on segments, which refuse a region of more than
255,637,165 bytes there, where the regions Linux and Windows collect on refuse none
that size, so `NoGCRegion` refuses a larger room on every runner and not only on macOS.
every runner gives under each framework. Under .NET 10 macOS collects on segments, which
refuse a region of more than 255,637,165 bytes there; under .NET 11 it collects on
regions (dotnet/runtime#125416), as Linux and Windows do under both, and regions refuse
none that size. So `NoGCRegion` refuses a larger room on every runner and framework, not
only on macOS under .NET 10: what segments give one region is a room both collectors give.
`TestAReadIsMeasuredExactlyWithABackgroundCollectionRunning` starts a background
collection before each repeat of that read and asks for the quiet figure, and its
guard needs the same read, counted without a region, to come out high, so that a
Expand Down Expand Up @@ -1051,6 +1060,12 @@ dotnet test -c Release # what CI runs, -warnaserror
dotnet run -c Release --project Benchmarks -- study <name> <args> # accuracy studies
```

The suite runs once for each target framework, net10.0 on the .NET 10 runtime and net11.0
on .NET 11, so both runtimes have to be installed; `--framework net10.0` runs one. Either
failing fails the run. A framework whose runtime is missing fails it too, with the host's
"You must install or update .NET", and only the exit code says so: the other framework's
summary still reads `Passed!`.

**A clean build is the only build that verifies.** Analyzers do not run on a project
MSBuild considers up to date, so a `-warnaserror` build after a small edit can report
zero errors on code that does not compile from scratch. A CA2014 — a `stackalloc`
Expand Down
22 changes: 15 additions & 7 deletions TestProbabilisticDataStructures/NoGCRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,23 @@ internal static class NoGCRegion

/// <summary>
/// The largest room every runner the suite runs on gives one region: what a 64-bit
/// workstation collector on segments, the one macOS runs, allows on 16 KiB pages.
/// workstation collector on segments, the one macOS runs under .NET 10, allows on
/// 16 KiB pages.
/// </summary>
/// <remarks>
/// macOS builds of the runtime collect on segments rather than regions: gcpriv.h
/// defines <c>USE_REGIONS</c> only for a 64-bit host that is not <c>__APPLE__</c> or
/// <c>__sun</c>, and not for a standalone collector (dotnet/runtime v10.0.14). On
/// segments, <c>gc_heap::prepare_for_no_gc_region</c> (gc.cpp) refuses as too large a
/// room past <c>(soh_segment_size - segment_info_size - eph_gen_starts_size) / 1.05</c>.
/// A workstation collector's segment is <c>INITIAL_ALLOC</c>, 256 MiB on a 64-bit host
/// Under .NET 10, macOS builds of the runtime collect on segments rather than regions:
/// gcpriv.h defines <c>USE_REGIONS</c> only for a 64-bit host that is not
/// <c>__APPLE__</c> or <c>__sun</c>, and not for a standalone collector (dotnet/runtime
/// v10.0.14). Under .NET 11 macOS collects on regions, as Linux and Windows do: the
/// guard admits <c>HOST_OSX</c> and still excludes the other Apple platforms (gcpriv.h at
/// v11.0.0, from dotnet/runtime#125416, first shipped in 11.0.0-preview.3). The suite
/// runs on both, so the room is the one segments give. That holds under .NET 11 too,
/// where every runner is on regions, and
/// <c>TestTheLargestRoomEveryRunnerGivesIsGiven</c> enters a region of exactly this
/// room on every runner under each framework. On segments,
/// <c>gc_heap::prepare_for_no_gc_region</c> (gc.cpp) refuses as too large a room past
/// <c>(soh_segment_size - segment_info_size - eph_gen_starts_size) / 1.05</c>. A
/// workstation collector's segment is <c>INITIAL_ALLOC</c>, 256 MiB on a 64-bit host
/// whatever its processors or memory, unless a hard limit or <c>GCSegmentSize</c> sets
/// another (<c>get_valid_segment_size</c>); the segment's own information takes one OS
/// page, 16 KiB on Apple silicon; and the generations' starts take two of the smallest
Expand Down
6 changes: 4 additions & 2 deletions TestProbabilisticDataStructures/TestAllocationMeasurement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ public void TestARoomPastTheLargestEveryRunnerGivesFailsOnEveryRunnerSayingSo()
/// <summary>
/// The largest room is given: work is counted in a region of exactly
/// <see cref="NoGCRegion.Largest"/>, so the bound refuses no room a runner gives. On
/// macOS, whose collector refuses a room past it, this checks its derivation.
/// macOS under .NET 10, whose collector refuses a room past it, this checks its
/// derivation; under .NET 11, where macOS collects on regions, it checks the bound still
/// holds there.
/// </summary>
[TestMethod]
public void TestTheLargestRoomEveryRunnerGivesIsGiven()
Expand All @@ -176,7 +178,7 @@ public void TestTheDefaultRoomIsOneEveryRunnerGives()
{
Assert.IsLessThanOrEqualTo(NoGCRegion.Largest, NoGCRegion.Room,
$"the default room, {NoGCRegion.Room:N0} bytes, is more than the {NoGCRegion.Largest:N0} " +
"macOS gives one region, so every measurement that takes it is refused there");
"macOS gives one region under .NET 10, so every measurement that takes it is refused there");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<!-- The library's frameworks, each tested: dotnet test runs the suite once per
framework, on that framework's runtime. -->
<TargetFrameworks>net10.0;net11.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,15 @@ public void TestWhatEveryReadMakesOnceIsChargedWhatItAllocates()
("the stream a byte array is read through", PersistenceFormat.ByteArrayStreamCost, () => new MemoryStream(bytes, writable: false)),
];

// The checksum's state is a System.IO.Hashing object, whose size is the package's
// and not the runtime's, so a failure says which one was loaded.
var hashing = typeof(Crc32).Assembly.GetName().Version;
foreach (var (what, charged, make) in made)
{
make();
Assert.AreEqual(charged, TestReadBudget.LeastAllocated(make, Repeats, null),
$"{what} is charged {charged:N0} bytes, and that is not what one allocates");
$"{what} is charged {charged:N0} bytes, and that is not what one allocates " +
$"(System.IO.Hashing {hashing} loaded, on .NET {Environment.Version})");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "10.0.100",
"version": "11.0.100",
"rollForward": "latestFeature"
}
}
Loading
Loading