Repository navigation
Generate generic math and modern interface members, and keep nullability out of paths - #102
Merged
Merged
Conversation
…ity out of paths The generator now writes the shape generic math is built on: an interface over itself with static abstract operators and properties, static virtual and default members, a struct that implements it, explicitly or not, and a method constrained to it. Plain interfaces gain static abstract and default-bodied properties, and static virtual and sealed members. Static abstract members now appear in about 400 of 1,000 generated libraries, where they were in 7. Comparing two libraries both ways then showed that a member's path took nullability from whichever version was new, as X6(T0?) one way and X6(T0) the other. Nullability is not part of a member's identity, so a path now leaves it out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mpdreamz
added a commit
that referenced
this pull request
Nov 14, 2026
…103) Benchmarks of reading, writing, parsing and comparing, with allocations, on `System.Collections.Immutable` and CoreLib (35,751 `.api` lines), using BenchmarkDotNet's `MemoryDiagnoser`. The profiles come from `dotnet-trace`. | CoreLib | Before | After | |---|---|---| | Read | 407 ms, 832 MB | 108 ms, 109 MB | | Write | 19 ms, 25 MB | 19 ms, 25 MB | | Parse | 160 ms, 120 MB | 122 ms, 72 MB | | Compare with its own `.api` file | **39 s, 4.4 GB** | 20 ms, 23 MB | On System.Collections.Immutable everything takes 2 ms or less: read 1.8 ms, write 0.45 ms, parse 1.2 ms, compare 0.36 ms. ## What was slow - **Compare:** - For every member and parameter it wrote both types out as C# to see whether they differed. - It built each member's report path from rendered parameter types, changed or not. - Writing a type looked at every member of the type it was in, so the cost grew with the square of the member count: `AdvSimd`, with 1,772 members, took 5.3 s alone. Now it compares the models structurally (`Same`), and writes C# and builds paths only for a change. It pairs members by a structural identity instead of a string key, checks attributes and constraints on the models first, and caches one `ApiDeclarationWriter` per type. - **Read:** - Decoding an attribute's enum argument, such as `[EditorBrowsable(EditorBrowsableState.Never)]`, scanned every type in the assembly. - Every attribute check built the attribute type's name again. Both are looked up once now. Nullable attributes are read from their blob instead of decoded the general way, primitive types and empty lists are shared, and names are compared in place. - **Parse:** - Each line was checked for a type declaration twice. - Every word was allocated twice, once to peek and once to take. - Each member got a new scope. ## What's left GC pauses are 45–60% of the remaining time. Reading or parsing builds a model that survives, and background GC handles that poorly. With `DOTNET_gcConcurrent=0`, CoreLib parses in 61 ms and reads in 105 ms. The tool now sets `<ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>`. A library can't choose its host's GC mode, so library callers keep the numbers in the table. ## Correctness - The CsCheck properties from #101 and #102 pass on this branch, including one soak run with 2,000 libraries per property and 800 pairs, so the faster paths give the same answers. - The Roslyn oracle, the round-trip and comparison snapshots, and the 630 tool tests pass. - `api/` gains the new public `ApiDeclarationWriter`, which `verifyapi` caught and the regenerated files record. Run the benchmarks with `dotnet run -c Release --project benchmarks/Nullean.PublicApi.Benchmarks -- --filter '*' --inProcess`. They run in-process because BenchmarkDotNet 0.15.8 doesn't recognise net11.0 when it launches a separate process. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Static abstract interface members and default interface bodies were rare in the generated libraries: static abstract members turned up in 7 of 1,000 and default bodies in 11. They're what modern .NET is built on, and generic math above all, so the generator now writes them on purpose.
Generator
where TSelf : IMath<TSelf>, sometimes alsoIEquatable<TSelf>) with static abstract operators (+,*,<,>) and properties (Zero), static abstract methods, static virtual and static members, and default instance members;readonly structthat implements it, sometimes through explicit implementation;sealedmembers.Per 1,000 libraries: static abstract members appear in 405, static virtual in 191, generic-math operators in 377, and default bodies in 51 methods and 22 properties.
What the mirror property found
A member's path took its nullability from whichever version was newer. So comparing in one direction gave
Extensions › X6(T0?), and in the otherX6(T0). Nullability isn't part of a member's identity, so a path now leaves reference-type annotations out (int?is a different type and stays).Checks: one soak run with 2,000 libraries per property and 800 pairs passed. The seed that found the path bug fails again with the old path.
mise run cipasses: 81 library tests and 630 tool tests.🤖 Generated with Claude Code