Skip to content

[mono] Array.IndexOf / Span<T>.IndexOf very slow on .net 7  #78008

Closed

Description

@gemSender

Description

I built mono and bcl with command
.\build.cmd mono+libs -rf Mono -a x64 -c release -rc release -lc release
and run performance test for Array.IndexOf/Span.IndexOf.
Surprisingly, the time-consuming of mono of .net7 is more than 5 times higher than that mono of .net6.
below is the code for test

using System;
using System.Diagnostics;

class Program
{
    private static int[] _testArray = InitAssistArray();

    private static int[] InitAssistArray()
    {
        int[] assistArray = new int[2048];
        Random r = new Random(5);
        for (int i = 0; i < assistArray.Length; i++)
        {
            assistArray[i] = r.Next() % 2048;
        }

        return assistArray;
    }
        
    public static int FindIndex(int n)
    {
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum += _testArray.AsSpan().IndexOf(i % 2048);
        }

        return sum;
    }

    public static void Main()
    {
        FindIndex(100);
        
        Stopwatch sw = Stopwatch.StartNew();
        int sum = FindIndex(100000);
        sw.Stop();
        Console.WriteLine($"time cost: {sw.ElapsedMilliseconds}");
    }
}

Configuration

os: windows
architecture: x64

Regression?

Data

it cost about
18 ms on .net6 coreclr
76 ms on .net6 mono
435 ms on .net7(rc2) mono

Analysis

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 8, 2022
  2. teo-tsirpanis commented on Nov 8, 2022

    @teo-tsirpanis
    Contributor

    Related to #75996?

  3. SamMonoRT commented on May 18, 2023

    @SamMonoRT
    Member

    @gemSender - this should be fixed in recent builds. Can we close this issue?

  4. removed
    untriagedNew issue has not been triaged by the area owner
    on May 18, 2023
  5. added this to the 8.0.0 milestone on May 18, 2023
  6. ghost locked as resolved and limited conversation to collaborators on Jun 18, 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