Override whole mapped object creation.

48 views
Skip to first unread message

Enrique Ferreyra

unread,
Dec 2, 2014, 6:12:42 AM12/2/14
to automapp...@googlegroups.com
Hello people.

We are starting to use the tool and some question arise on the team, lets start from the beginning.

We are concerned about eventually some perfomance issue in the standar mapping like:
Mapper.CreateMap<Customer, CustomerViewItem>();

Lets say i have a lot of places with this code:
CustomerViewItem cvii = Mapper.Map<Customer, CustomerViewItem>(customer);

Now because performace starts to be a issue we want to change the standar behavior for a custom old plain new () and Property to Property assingment.

How can i do that without replacing the second line of code and getting a nice performance boost ?

I read about custom value resolver, but im not sure if it applies to a single property or the whole object creation, im learning.

Thanks!

Jimmy Bogard

unread,
Dec 4, 2014, 7:25:24 AM12/4/14
to automapper-users
What performance issue are you seeing?

--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Enrique Ferreyra

unread,
Dec 4, 2014, 11:40:52 AM12/4/14
to automapp...@googlegroups.com
Hi, as i said its about some eventual performance issue and how to handle it when it comes, but anyway my test throw this results:

One million POCO objects:

Default Mapper.Map -> 33000  milliseconds

Mapper.Map with CustomTypeConverter -> 2500 milliseconds

Plain old properties assignment -> 153 milliseconds

Using: <package id="AutoMapper" version="3.3.0" targetFramework="net40" />

Jimmy Bogard

unread,
Dec 4, 2014, 3:06:29 PM12/4/14
to automapper-users
Gotcha, and are you using AutoMapper where you're pulling objects from a DB?

Enrique Ferreyra

unread,
Dec 9, 2014, 8:39:04 AM12/9/14
to automapp...@googlegroups.com
Not in the test, but yes in real development, im using it for several maps:

From wcf contract objects (DTOs) to business model object and reverse.

From business model object to entity framework objects (database first) and reverse.

Also we noted that mapping a whole collection is slighter slow than doing a foreach and map individual object, no big deal anyway.


As architect i usually get called when a develpment is put in production and performance issues arise, so i want to have handy tips to tweak in this cases.

Jimmy Bogard

unread,
Dec 9, 2014, 8:47:54 AM12/9/14
to automapper-users
For a million objects, how much time is spent communicating with the database? Is that part of the total time calculation?

Enrique Ferreyra

unread,
Dec 19, 2014, 4:28:09 PM12/19/14
to automapp...@googlegroups.com
Its a fair point, i want to add this tip for .Net 4+

Default Mapper.Map -> 33000  milliseconds

The same but with Parallel.ForEach() instead a foreach: 1915 milliseconds

WOW !

Original:
            foreach (var item in all)
                AutoMapper.Mapper.Map<TheDestinationClass>(item);

Using the new .Net 4 Task Parallel Library (TPL):

            Parallel.ForEach(all, item =>
                AutoMapper.Mapper.Map<TheDestinationClass>(item));

Jimmy Bogard

unread,
Dec 19, 2014, 5:44:34 PM12/19/14
to automapper-users
um....success?

Michael Powell

unread,
Dec 19, 2014, 6:03:02 PM12/19/14
to automapp...@googlegroups.com


On Friday, December 19, 2014 3:28:09 PM UTC-6, Enrique Ferreyra wrote:
Its a fair point, i want to add this tip for .Net 4+

Default Mapper.Map -> 33000  milliseconds

The same but with Parallel.ForEach() instead a foreach: 1915 milliseconds

WOW !

With cores, processing, and threads being what it is today, you are at all surprised? 

Enrique Ferreyra

unread,
Dec 22, 2014, 8:19:48 AM12/22/14
to automapp...@googlegroups.com
You have to see what a piece of 'core' is my development computer >.<

Michael Powell

unread,
Dec 22, 2014, 8:21:46 AM12/22/14
to automapp...@googlegroups.com
On Mon, Dec 22, 2014 at 7:19 AM, Enrique Ferreyra <efer...@gmail.com> wrote:
> You have to see what a piece of 'core' is my development computer >.<

I've seen one or two 386 benchmarks, event still today... :)
> You received this message because you are subscribed to a topic in the
> Google Groups "AutoMapper-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/automapper-users/LXqYZfFzkss/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
Reply all
Reply to author
Forward
0 new messages