Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The frame times of my toy ray tracer increased from 24ms to 30ms #78127

Closed
Tracked by #33658
BTOdell opened this issue Nov 9, 2022 · 6 comments
Closed
Tracked by #33658

The frame times of my toy ray tracer increased from 24ms to 30ms #78127

BTOdell opened this issue Nov 9, 2022 · 6 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI regression-from-last-release tenet-performance Performance related issue
Milestone

Comments

@BTOdell
Copy link

BTOdell commented Nov 9, 2022

Description

I was encouraged to open an issue here by people on Reddit: https://www.reddit.com/r/csharp/comments/ypqn03/net_7_is_out_now/ivl99xy/

Here is the link to my repo: https://github.com/BTOdell/SharpRay

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):
image

.NET 7.0.100 (target net6.0):
image

.NET 7.0.100 (target net7.0):
image

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?

@BTOdell BTOdell added the tenet-performance Performance related issue label Nov 9, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 9, 2022
@AndyAyersMS
Copy link
Member

AndyAyersMS commented 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 csproj

  <PropertyGroup>
    <TieredCompilationQuickJitForLoops>false</TieredCompilationQuickJitForLoops>
  </PropertyGroup>

When 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 AndyAyersMS added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed untriaged New issue has not been triaged by the area owner labels Nov 9, 2022
@ghost
Copy link

ghost commented Nov 9, 2022

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I was encouraged to open an issue here by people on Reddit: https://www.reddit.com/r/csharp/comments/ypqn03/net_7_is_out_now/ivl99xy/

Here is the link to my repo: https://github.com/BTOdell/SharpRay

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):
image

.NET 7.0.100 (target net6.0):
image

.NET 7.0.100 (target net7.0):
image

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?

Author: BTOdell
Assignees: -
Labels:

tenet-performance, area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member

Related: #67594.

@AndyAyersMS
Copy link
Member

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.

image

Corresponding profile from .NET 6

image

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.

@AndyAyersMS
Copy link
Member

This seems to be fixed with latest .NET 8 builds (will be available in Preview 4)

;; 7.0
Framebuffer size: <800, 800>
Rendered in: 138.3371ms
Rendered in: 115.2097ms
Rendered in: 60.8962ms
Rendered in: 27.6196ms
Rendered in: 27.1536ms
Rendered in: 27.0591ms
Rendered in: 27.4292ms
Rendered in: 27.1339ms
Rendered in: 27.1519ms

;; 8.0 current main
Framebuffer size: <800, 800>
Rendered in: 133.7311ms
Rendered in: 108.3345ms
Rendered in: 65.7654ms
Rendered in: 24.2893ms
Rendered in: 26.8595ms
Rendered in: 24.5418ms
Rendered in: 23.7889ms
Rendered in: 24.2502ms
Rendered in: 23.6659ms
Rendered in: 23.9037ms
Rendered in: 23.8969ms

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.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI regression-from-last-release tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

4 participants