Skip to content

Speed up rewriting large test projects - #8

Merged
yevhen merged 1 commit into
yevhen:mainfrom
ivank-ys:perf/rewrite-task-speed
Dec 3, 2026
Merged

yevhen merged 1 commit into
yevhen:mainfrom
ivank-ys:perf/rewrite-task-speed

Conversation

@ivank-ys

@ivank-ys ivank-ys commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

On a large test project the SharpAssert rewrite step took longer than the C# compiler itself. For every source file the task loaded the same five metadata references again and built the semantic model, one file at a time. This PR loads the references once and rewrites files in parallel. The rewritten output does not change.

Measured on a real test suite (Apple M4 Pro, 14 cores), with the stock 2.0.0 task and this branch:

Scenario 2.0.0 This PR
Rewrite step, one test project with ~390 rewritten files (~4,300 tests), after editing one file 10.8 s 2.4 s
Rewrite step, clean build of two large test projects 15.5 s 3.9 s
Whole clean build of those two projects 27.0 s 18.4 s

For comparison, Csc took 5.3–6.9 s on the first project, so before this change rewriting cost more than compiling.

Output check: all 389 generated .sharp.g.cs files of the large project are byte-for-byte the same as with 2.0.0. test-local.sh, including package tests, passes.

Merge Danger

Reversibility: reversible

Blast Radius: build time only. Each file is still rewritten on its own, so running files in parallel cannot change the output. A file that fails to rewrite still falls back to the original source with a warning.

The rewriter loaded the same five metadata references for every source
file and processed files one at a time. On test projects with hundreds
of files it took longer than the C# compiler itself.

References are now loaded once and files are rewritten in parallel.
The rewritten output is byte-for-byte the same.
@yevhen
yevhen merged commit 577a594 into yevhen:main Dec 3, 2026
1 of 3 checks passed
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.

2 participants