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!
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With