You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The frame times of my toy ray tracer increased from 24ms to 30ms #78127
With the GA release of .NET 7, I decided to upgrade the version of my toy ray tracing project from .NET 6.0.403 to 7.0.100 in the hopes that I could get some "free" performance with the new version.
Unfortunately, the frame times of my app increased from 24ms to 30ms on my machine when I change the target framework from 6.0 to 7.0.
Configuration
.NET versions: 6.0.403 and 7.0.100
OS: Windows x64 build 19043
CPU: Intel i9-9960X with 64GB DDR4-3600
Regression?
The regression appears to happen when targeting a newer framework: net6.0 to net7.0
If the target framework is set to net6.0, then the performance is the same on both versions of the runtime.
Images
.NET 6.0.403 (target net6.0):
.NET 7.0.100 (target net6.0):
.NET 7.0.100 (target net7.0):
dotnet restore was used before each run to ensure the correct configuration was applied.
Analysis
Sorry if this issue isn't related to the runtime. It might have to do with the C# language compilation to IL?
This is a result of the new On-Stack Replacement feature (aka OSR) in .NET 7. You can disable this feature by adding the following lines to your csproj
Profile of 20 seconds of the app on .NET 7 (with default behavior)
I think perfview's attribution of Run as "ReadyToRun" is wrong, this is OSR code.
Corresponding profile from .NET 6
Looking at Run the inner loop codegen is actually fairly similar, except that the OSR method seems to have realized that Vec4.One is a constant -- but then it fails to hoist/CSE this constant and reloads it repeatedly. That might be the regression. It's possible hoisting is thrown off by lack of a preheader or something.
Activity
AndyAyersMS commentedon Nov 9, 2022
This is a result of the new On-Stack Replacement feature (aka OSR) in .NET 7. You can disable this feature by adding the following lines to your
csprojWhen I do this, I see ~5% faster times for .NET 7.
[edit: fixed the property name and value]
FYI @dotnet/jit-contrib -- I have not yet drilled in to see where OSR is losing perf.
AndyAyersMS commentedon Nov 9, 2022
Related: #67594.
AndyAyersMS commentedon Nov 10, 2022
Profile of 20 seconds of the app on .NET 7 (with default behavior)
I think perfview's attribution of Run as "ReadyToRun" is wrong, this is OSR code.
Corresponding profile from .NET 6
Looking at
Runthe inner loop codegen is actually fairly similar, except that the OSR method seems to have realized thatVec4.Oneis a constant -- but then it fails to hoist/CSE this constant and reloads it repeatedly. That might be the regression. It's possible hoisting is thrown off by lack of a preheader or something.AndyAyersMS commentedon Mar 31, 2023
This seems to be fixed with latest .NET 8 builds (will be available in Preview 4)
I' m going to close this. @BTOdell once Preview 4 is out give it a try and see if you see the same. If not, please re-open.