Search code examples
c#.netmemory-leaksautomapperautomapper-3

AutoMapper hurting performance in .net application having more than 1327 DTO while mapping


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.


Solution

  • 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.