fluentsprings / ExpressMapper

Mapping .Net types
http://www.expressmapper.org
Other
309 stars 65 forks source link

Performance difference between v1.8.3 and v1.9.1 #149

Open SteveWilkes opened 6 years ago

SteveWilkes commented 6 years ago

Hi,

I've got an ongoing mapper performance project, and it looks like something happened to ExpressMapper between versions 1.8.3 and 1.9.1 which made it much slower mapping non-simple mappings, possibly collections. The two tests in question are:

I'm intending to write a follow-up blog with updated performance results, so wanted to give you a heads up about this before I do.

All the best,

Steve Wilkes

anth12 commented 5 years ago

They aren't strictly like-for-like, take for example ExpressMapper vs AutoMapper; the AutoMapper registration is cfg.CreateMap<Foo, Foo>() whereas the ExpressMapper registration uses custom Member mappings e.g. .Member(foo => foo.Foos, foo => foo.Foos != null ? foo.Foos.Map<List<Foo>, List<Foo>>() : new List<Foo>()).

I tried running the tests and do get very high times for ExpressMapperComplexTypeMapper & ExpressMapperDeepMapper, however when removing the custom member mappings to make it a fair test with the others (and removing the assertions) I get the following results.

AutoMapperComplexTypeMapper 9.8261461 ExpressMapperComplexTypeMapper 143.674907

AutoMapperDeepMapper 1.4314013 ExpressMapperDeepMapper 133.096825

With custom member mappings removed:

AutoMapperComplexTypeMapper 10.4125455 ExpressMapperComplexTypeMapper 6.3748084

AutoMapperDeepMapper 1.3606325 ExpressMapperDeepMapper 1.9715963

It seems there is a performance issue but it looks isolated to custom member mappings.

SteveWilkes commented 5 years ago

Hi!

Thanks for the info!

I added the collection member mappings to create empty collections instead of leaving the properties null. For example in the Deep mapper test, if I map new Customer { Name = "Steve" } to a CustomerDto, the result object's Addresses and AddressesArray are both null with ExpressMapper, but populated with empty collections with AutoMapper and AgileMapper.

I may well have not done it in the best way - is there a better way you can suggest?

Cheers,

Steve