AutoMapper 5.0 speed increases

Just an update on the work we’ve been doing to speed up AutoMapper. I’ve captured times to map some common scenarios (1M mappings). Time is in seconds:

  Flattening Ctor Complex Deep
Native 0.0148 0.0060 0.9615 0.2070
5.0 0.2203 0.1791 2.5272 1.4054
4.2.1 4.3989 1.5608 134.39 29.023
3.3.1 4.7785 1.3384 72.812 34.485
2.2.1 5.1175 1.7855 122.0081 35.863
1.1.0.118 6.7143 n/a 29.222 38.852

The complex mappings had the biggest variation, but across the board AutoMapper is *much* faster than previous versions. Sometimes 20x faster, 50x in others. It’s been a ton of work to get here, mainly from the change in having a single configuration step that let us build execution plans that exactly target your configuration. We now build up an expression tree for the mapping plan based on the configuration, instead of evaluating the same rules over and over again.

We *could* get marginally faster than this, but that would require us sacrificing diagnostic information or not handling nulls etc. Still, not too shabby, and in the same ballpark as the other mappers (faster than some, marginally slower than others) out there. With this release, I think we can officially stop labeling AutoMapper as “slow” ;)

Look for the 5.0 release to drop with the release of .NET Core next week!

About Jimmy Bogard

I'm a technical architect with Headspring in Austin, TX. I focus on DDD, distributed systems, and any other acronym-centric design/architecture/methodology. I created AutoMapper and am a co-author of the ASP.NET MVC in Action books.
This entry was posted in AutoMapper. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Josh

    Great work – how’s the startup performance? Is there a way to precompile the plans?

    • jbogard

      We actually opt to lazily compile the plans. We build the expression tree but compile on first use. Compiling can be intensive so those with hundreds of maps would see lousy startup times.

      • Sam Bauwens

        I’m in the process of upgrading our WebAPI project to the latest version (5.1.1), and indeed we get a big startup hit for multiple of our pages. AutoMapper takes 5-10s the first time it maps, but that’s repeated for multiple pages. Is there a way to opt out of lazy compilation in production and compile everything at startup?

        • jbogard

          Can you open a GitHub issue for this? Other people might have this question too, I think.

          • Sam Bauwens

            Ok, here is the github issue

  • Very impressive numbers!

  • Sean Fisher

    Does this support PCLs?

    • jbogard

      Yes.

  • Stefan de Vogelaere

    Has the performance on Xamarin.Android increased? This was a show stopper for me in 4.x – I actually removed AutoMapper because of the bad performance

    • jbogard

      Yes, all platforms are using the same mapping code now. In android before it was using reflection. Which is slow.

  • SteveMets

    Are there any complete samples for Version 5? I have set it up based on all the bits and pieces, and don’t seem to get it working. So far, getting ‘Missing type map configuration or unsupported mapping’, when using EF6 objects- actually the exact same tables in 2 different DbContexts, databases. I tried setting ProxyCreationEnabled = false, but that did not fix it. I used version 3 some years ago, and it was very easy to use, if a little slow in some cases. I would really like to get on board with it again. Thanks

    • jbogard

      My ContosoUniversity project (check my GitHub) is a good place to start.

      • SteveMets

        Hi Jimmy; I did not see that on GitHub; is it in another location than the Automapper repository?

        • jbogard

          My github is github.com/jbogard

        • SteveMets

          Thanks!

  • Yuriy

    Congrats Jimmy! :)