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

折月煮酒 提交于 2020-01-06 04:01:27

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/37392182/automapper-hurting-performance-in-net-application-having-more-than-1327-dto-whi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!