Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automapper running extremely slow on mapping 1400 records

Tags:

c#

asp.net

c#-4.0

I am using AUtomapper which I am very impressed with however, I have a complex object with many nested collections. I'm using Telerik OpenAccess and it returns the 1400 records fast but when I pass it to Automapper and it slows to a ridiculous crawl. Here is my code for reference:

        List<DAL.Event> query = httpContext.Events.Where(e => e.Inactive != true && e.Event_Locations != null).ToList();
        Mapper.CreateMap<DAL.Event, EventDTO>();
        Mapper.CreateMap<DAL.Event_Association, EventAssociationDTO>();
        Mapper.CreateMap<DAL.Event_ExecutingUnit, EventExecutingUnitDTO>();
        Mapper.CreateMap<DAL.Event_Funding, EventFundingDTO>();
        Mapper.CreateMap<DAL.Event_Location, EventLocationDTO>();
        Mapper.CreateMap<DAL.Event_Objective, EventObjectiveDTO>();
        Mapper.CreateMap<DAL.Event_OSR, EventOSRDTO>();
        Mapper.CreateMap<DAL.Event_PaxBreakDown, EventPAXBreakDownDTO>();
        Mapper.CreateMap<DAL.Event_RegionalConsideration, EventRegionalConsiderationDTO>();
        Mapper.CreateMap<DAL.Event_ReviewStatus, EventReviewStatusDTO>();
        Mapper.CreateMap<DAL.Event_SPCalendarClone, EventSPCalendarClonesDTO>();
        Mapper.CreateMap<DAL.Event_Task, EventTasksDTO>();
        Mapper.CreateMap<DAL.Event_TSO, EventTSOsDTO>();
        Mapper.AssertConfigurationIsValid();
        Mapper.AllowNullDestinationValues = true;

        IList<EventDTO> result = Mapper.Map<List<DAL.Event>, List<EventDTO>>(query);
        return result;

HELP!

like image 507
Ryan Avatar asked Nov 09 '10 08:11

Ryan


2 Answers

I benchmarked automapper. A single core of a 2.0GHz Xeon is able to handle 85,000 maps per second, on a small object (3 properties). It was 60 times slower than manually copying the properties. If you'd like, I can benchmark other values for you.

like image 125
Bryan Boettcher Avatar answered Sep 22 '22 15:09

Bryan Boettcher


There was a team at my previous job who were also using Automapper but in the end they removed it because of the performance impact.

I think in this specific scenario it's best to write the mapping code yourself, or start replacing them one by one. Maybe one mapping is causing the bad performance?

like image 30
Gerrie Schenck Avatar answered Sep 22 '22 15:09

Gerrie Schenck