Slow generation on .NET 6
See original GitHub issueWhen switching from .NET 5 to .NET 6, the Generate method takes over an order of magnitude longer, even for very simple records (e.g. Foo(int Bar)).
| Job | Runtime | Mean | Error | StdDev | Ratio | RatioSD |
|---|---|---|---|---|---|---|
| .NET 5.0 | .NET 5.0 | 7,574.85 ns | 45.050 ns | 42.139 ns | 1.00 | 0.00 |
| .NET 6.0 | .NET 6.0 | 367,589.88 ns | 2,163.086 ns | 2,023.352 ns | 48.53 | 0.27 |
Bogus does not show the same performance difference as AutoBogus:
| Job | Runtime | Mean | Error | StdDev | Ratio | RatioSD |
|---|---|---|---|---|---|---|
| .NET 5.0 | .NET 5.0 | 82.71 ns | 0.111 ns | 0.104 ns | 1.00 | 0.00 |
| .NET 6.0 | .NET 6.0 | 71.28 ns | 0.378 ns | 0.353 ns | 0.86 | 0.00 |
I have created a Gist with the code used to generate this benchmark.
It sounds odd that no one has noticed it before, so perhaps I’m using it wrong?
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:6
Top Results From Across the Web
NET6 performance issue (compared to .NET5) #63621
After the migration the application is slow (4-5 times slower). It's not any particular part of the code that has slowed down the...
Read more >Performance Improvements in .NET 6
Code generation is the foundation on top of which everything else is built. As such, improvements to code generation have a multiplicative ...
Read more >Visual studio 22 slow Build time with .net core 6
net core 2.1 to .net core 6.0, the build time became slow,takes about 1:30 (1 minute and 30 seconds) . by using MSBuild...
Read more >.NET 6 hello world extremely slow : r/csharp
When I try to run in command promt it takes 6~9 seconds to show the hello world text. Tried same in my friends...
Read more >Improving logging performance with source generators
NET 6. In this post I look at the new LoggerMessage source generator, showing how and when to use it. I start by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Unfortunately, I didn’t find a way to fix it 😞 I simply noticed that tests weren’t failing anymore when sharing a single generated instance, so I’m just generating it once per test class, instead of once per test as I had to do before.
I can’t see the public source code on GitHub (dead links in the NuGet page). If you want to try it yourself, the gist above contains two files: the C# project and the BenchmarkDotNet test.
Tried the benchmark and I get similar results with both AutoBogus 2.13.1 and AutoBogusLifeSupport 2.14.0. To be honest I didn’t see anything in the code to suggest that it would behave differently in this case, but it was worth a try 😃