Skip to content

Compile xUnit v3 solutions in-process with Roslyn (~5x faster with the whole stack) - #332

Open
iHiD wants to merge 1 commit into
csharp-project-shapesfrom
csharp-roslyn-fast-path
Open

iHiD wants to merge 1 commit into
csharp-project-shapesfrom
csharp-roslyn-fast-path

Conversation

@iHiD

@iHiD iHiD commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Hello 🙂 I'm working with Claude to try and get our tooling faster.

This PR is the last of three that together make this project around 5x faster. I've run it in production to benchmark things in the real world against the most recent few hundred solutions, so I'm confident that it works robustly. However, I've not written the code. I have tried my hardest to get Claude to write sensible messages and comments that explains stuff, but I'd ask for your patience in the fact I'm sending AI code to you. Everything below here is from your friendly neighbourhood LLM...


This is the third of three PRs. Merge them in order: #330, then #331, then this one (#332).

What changed

This has been tested in production, and with all three PRs merged it has reduced the median run from 9.0s to 1.8s.

When MSBuild still runs

In each of these cases, the runner prints Fast path not used: <reason> and builds with MSBuild:

  • The .csproj matches no shape. If the track changes an exercise's .csproj, the new version will match no shape until someone adds it (the README explains how). It also happens for a project file with conditions, imports, targets or item types other than Using and PackageReference.
  • The solution folder has a bin or obj folder, another project file, a Directory.Build.* or Directory.Packages.props file, global.json, nuget.config, AssemblyInfo.cs, a .resx or .globalconfig file, or an .editorconfig with diagnostic settings.
  • A source file is not valid UTF-8, uses a feature that requires a source generator (such as [GeneratedRegex]), or has a [Fact] or [Theory] outside the test file. The runner finds these while it reads the source files, so these solutions take slightly longer than they would with Run the xUnit v3 test executable directly instead of through dotnet test (~45% faster) #330 alone.

🤖 Generated with Claude Code

The runner now first tries a fast path. It reduces the solution's
.csproj to a key, finds the project shape with the same key, and
compiles the solution with Roslyn inside its own process, using that
shape's compiler arguments and generated files. It then runs the test
executable against the shape's precompiled dependencies. This skips
`dotnet restore` and `dotnet build`.

If the fast path can't handle the solution, the runner prints the
reason and builds with MSBuild as before. Setting EXERCISM_FAST_PATH=off
turns the fast path off. The README explains both ways and how to add a
new shape.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ErikSchierboom
ErikSchierboom force-pushed the csharp-roslyn-fast-path branch from 9315f2c to ecbe613 Compare November 18, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant