1

We are using AutoMapper 3.1.1.0 in our Dot net application. We are having lots of classes which neeed to map. Time required to initialize mapping is almost 22 seconds. We are having almost 1327 DTO which need to mapped.

And we can say that each DTO having average 8 properties.

My concern is for each message we check in list of 1327 mapped DTO,
and then use

 if (MappingManager.MessageMappings.ContainsKey(message.GetType()))
            {
                var myMessage = Mapper.Map(message, message.GetType(), MappingManagerFile.MessageMappings[message.GetType()]);

So it hurts performance. Do we need to Dispose after use, or automapper take care itself? In task manager the component which do this conversion is taking lots of memory.

So please suggest what alterantives we need to use to improve performance.

DevPerson
  • 399
  • 1
  • 6
  • 21
  • * Why an old version and * what is 22 seconds startup (!) time an issue when this happens once at program start and can be done async while doing other startup things? – TomTom May 23 '16 at 13:28
  • *"Time required to initialize mapping is almost 22 seconds"*, can you show code, can you determine which type take longer, etc? – Sinatr May 23 '16 at 13:28
  • @Sinatr My concern is not at start time required, but after actual request come and we need to map that using Mapper.Map and search in those 1300 list records – DevPerson May 23 '16 at 13:30

2 Answers2

0

Having that many entities mapped with automapper is going to take some time. Are you eager loading your entities or using lazy loading? I have seen these issues in the past when using lazy loading as Automapper generates a large number of database hits when getting all of the relational data.

Eager loading may be your best bet here, or I would recommend only loading exactly what you need. Seems like a lot of data to load at once.

hawkstrider
  • 4,141
  • 16
  • 27
  • @bhmhler Thank you for explanation, but can you tell me that AutoMapper take care of disposing the objects or should we need to write. and Loading time is not concern. Concern is when request came, we need to intercept and checking the existence and then Map – DevPerson May 23 '16 at 13:32
  • Automapper will generate the mapped object and if there is that much data in the DTO's, you are going to get a lot of memory usage. You should be disposing of your message model and the automapped model when you are done with it. I don't think this is really related to Automapper itself, but rather the objects you are creating need to be disposed. – hawkstrider May 23 '16 at 13:35
  • Yes, I will try in that way :) thanks for clarification – DevPerson May 23 '16 at 13:37
0

Later versions of AutoMapper lazily compile the configuration. There's still some startup time, discovering and mapping types, but compiling the runtime mapping function is done lazily.

I would suggest trying the 5.0 release and comparing the numbers.

Jimmy Bogard
  • 26,045
  • 5
  • 74
  • 69