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

Strange performance degradation in .net core 3.1 #32973

Closed
B-Esmaili opened this issue Feb 27, 2020 · 5 comments
Closed

Strange performance degradation in .net core 3.1 #32973

B-Esmaili opened this issue Feb 27, 2020 · 5 comments
Labels
tenet-performance Performance related issue untriaged New issue has not been triaged by the area owner

Comments

@B-Esmaili
Copy link

B-Esmaili commented Feb 27, 2020

I was benchmarking AutoMapper in .net core 3.1 and found out a strange performance degradation in .net core 3.1 with respect to .net core 2.1 here is the screenshot from my benchmark :

.NET CORE 3.1
image

.NET CORE 2.0
netcore21

and following is code for my benchmark if anyone interested :

using AutoMapper;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Collections.Generic;
using System.IO;

namespace ConsoleApp5
{


    public class Model1
    {
        public int number { get; set; }

        public double dlb;

        public DateTime dateTime;

        public string str;
    }

    public class Model2
    {
        public int number { get; set; }

        public double dlb;

        public DateTime dateTime;

        public string str;
    }
    [MemoryDiagnoser]
    public class Test
    {
        [Benchmark]
        public void AutoMap()
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<Model1, Model2>();
            });

            Random rnd = new Random();
            Model1 m1 = new Model1();
            List<Model2> m2List = new List<Model2>();
            var mapper = configuration.CreateMapper();

            for (int i = 0; i < 1000000; i++)
            {
                m1.number = rnd.Next(0, 5000);
                m1.dlb = rnd.NextDouble() * 50000;
                m1.dateTime = DateTime.Now;
                m1.str = "SOME TEXT TO RUN BENCHMARK";

                Model2 m2 = new Model2();
                mapper.Map<Model1, Model2>(m1, m2);
                m2List.Add(m2);
            }
        }
        [Benchmark]
        public void MapByHand()
        {
            Random rnd = new Random();
            Model1 m1 = new Model1();
            List<Model2> m2List = new List<Model2>();

            for (int i = 0; i < 1000000; i++)
            {
                m1.number = rnd.Next(0, 5000);
                m1.dlb = rnd.NextDouble() * 50000;
                m1.dateTime = DateTime.Now;
                m1.str = "SOME TEXT TO RUN BENCHMARK";

                Model2 m2 = new Model2();
                m2.dateTime = m1.dateTime;
                m2.dlb = m1.dlb;
                m2.number = m1.number;
                m2.str = m1.str;

                m2List.Add(m2);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            BenchmarkRunner.Run<Test>();                       
        }
    }
}

not only benchmark result is better is .net core 2.1 but the benchmark itself toke less time to run with respect to .net core 3.1. could anyone from .net team describe about the situation?
thanks.

@scalablecory
Copy link
Contributor

Thanks. The next step would probably be to isolate the .NET components that are being hit: Random and DateTime.Now.

@scalablecory scalablecory transferred this issue from dotnet/core Feb 28, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Feb 28, 2020
@scalablecory scalablecory added the tenet-performance Performance related issue label Feb 28, 2020
@scalablecory
Copy link
Contributor

@tarekgh any changes to DateTime.Now in 3.x?

@karelz
Copy link
Member

karelz commented Feb 28, 2020

@adamsitnik can you please help here?

@stephentoub
Copy link
Member

My guess would be it's the same as #13091, i.e. leap-seconds support.

@tarekgh
Copy link
Member

tarekgh commented Feb 28, 2020

Right, this is leaping second support which comes with some extra cost.

@B-Esmaili can you try the work around on #13091 (comment) and look if this will get rid of the regression?

I am going to cliose this issue for now as a duplicate with #13091 but feel free to respond back if you think otherwise.

@tarekgh tarekgh closed this as completed Feb 28, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tenet-performance Performance related issue untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

6 participants