Skip to content

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

Closed

Description

@BTOdell

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?

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 9, 2022
  2. AndyAyersMS commented on Nov 9, 2022

    @AndyAyersMS
    Member

    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.

  3. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 9, 2022
  4. AndyAyersMS commented on Nov 9, 2022

    @AndyAyersMS
    Member

    Related: #67594.

  5. AndyAyersMS commented on Nov 10, 2022

    @AndyAyersMS
    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.

  6. added this to the 8.0.0 milestone on Nov 10, 2022
  7. AndyAyersMS commented on Mar 31, 2023

    @AndyAyersMS
    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.

  8. ghost locked as resolved and limited conversation to collaborators on Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions