Skip to content

Latest commit

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Mappee - Fastest avaiable mapper for .NET

GitHub licenseFirst TimersCodeFactorNuget

Mappee is a high performance object-to-object mapper for .NET. It is a simple and easy to use library that can be used to map objects of different types. It is designed to be fast and efficient, and it is the fastest available mapper for .NET. The main idea is to map objects using precompiled code, which makes it much faster than other mappers that use reflection. Generated code is cached, so it is only generated once for each type pair, and then reused for all subsequent mappings.

Features

  • Fast and efficient
  • Simple and easy to use

Getting Started

Using static methods

Mapper.Bind<TestObject,TestObjectDto>().IgnoreMember<TestObject,TestObjectDto>(e =>e.Name);.BeforeMap<TestObject,TestObjectDto>((source,_)=>{source.Nickname=$"{source.FirstName}{source.LastName}".ToLower();}).AfterMap<TestObject,TestObjectDto>((_,destination)=>{destination.Char=destination.FirstName.First();}).Bind<TestObjectModification,TestObjectModificationDto>().Bind<TestObjectField,TestObjectFieldDto>().Bind<TestObjectLink,TestObjectLinkDto>().Compile();vartestObject=newTestObject();vartestObjectDto=Mapper.Map<TestObjectDto>(testObject);

Using dependency injection

varservicesCollection=newServiceCollection();servicesCollection.AddMappee(profile =>{profile.Bind<TestObject,TestObjectDto>().IgnoreMember<TestObject,TestObjectDto>(e =>e.Name).BeforeMap<TestObject,TestObjectDto>((source,_)=>{source.Nickname=$"{source.FirstName}{source.LastName}".ToLower();}).AfterMap<TestObject,TestObjectDto>((_,destination)=>{destination.Char=destination.FirstName.First();});//invoke compile method is not necessary, it will be called automatically});//[...]varserviceProvider=servicesCollection.BuildServiceProvider();varscope=serviceProvider.CreateScope();varmapper=scope.ServiceProvider.GetRequiredService<IMapper>();vartestObject=newTestObject();vartestObjectDto=mapper.Map<TestObject,TestObjectDto>(testObject);

Mappee vs other mappers (performance comparison)

Benchmarks

2500 items in 3 different collections and 2500 nested objects (like linked list)

Performance Comparison 2500

BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3155/23H2/2023Update/SunValley3)
12th Gen Intel Core i7-12700K, 1 CPU, 20 logical and 12 physical cores
.NET SDK 8.0.101
[Host] : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0 
MethodItemsMeanErrorStdDevRatioRankGen0Gen1Gen2AllocatedAlloc Ratio
AutoMapper25001,697.0 μs33.92 μs58.50 μs1.001144.5313142.578135.15631.5 MB1.00
TinyMapper2500426.8 μs1.94 μs1.82 μs1.00199.121149.3164-1.24 MB1.00
Mappee2500268.0 μs2.85 μs2.67 μs1.001140.625093.2617-1.75 MB1.00
Handwritten2500233.5 μs4.08 μs3.62 μs1.001122.070366.4063-1.52 MB1.00

1,5,20 items in 3 different collections and 1,5,20 nested objects (like linked list)

Performance Comparison 1,5,20

BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3155/23H2/2023Update/SunValley3)
12th Gen Intel Core i7-12700K, 1 CPU, 20 logical and 12 physical cores
.NET SDK 8.0.101
[Host] : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0 
MethodItemsMeanErrorStdDevRatioRankGen0Gen1AllocatedAlloc Ratio
AutoMapper5928.6 ns12.45 ns11.64 ns1.0010.27750.00293.55 KB1.00
TinyMapper5930.4 ns9.43 ns8.82 ns1.0010.23560.00193.01 KB1.00
Mappee5457.6 ns9.17 ns10.56 ns1.0010.32520.00294.16 KB1.00
Handwritten5368.8 ns1.90 ns1.58 ns1.0010.28130.00243.59 KB1.00
AutoMapper101,663.7 ns14.35 ns13.42 ns1.0010.53020.00956.79 KB1.00
TinyMapper101,708.8 ns18.58 ns17.38 ns1.0010.43870.00575.6 KB1.00
Mappee10832.1 ns13.57 ns12.70 ns1.0010.61130.00957.8 KB1.00
Handwritten10683.4 ns5.36 ns4.75 ns1.0010.53020.00766.77 KB1.00
AutoMapper203,082.1 ns13.87 ns12.30 ns1.0011.03760.034313.26 KB1.00
TinyMapper203,334.9 ns65.42 ns77.87 ns1.0010.83920.022910.72 KB1.00
Mappee201,575.2 ns31.47 ns52.58 ns1.0011.17680.034315.03 KB1.00
Handwritten201,313.9 ns15.95 ns14.14 ns1.0011.02230.028613.06 KB1.00

Supported platforms

  • .NET 8.0
  • .NET 7.0
  • .NET 6.0
  • .NET Standard 2.1
  • .NET Standard 2.0
  • .NET Framework 4.8.1

About

Mappee - Fastest avaiable mapper for .NET (AutoMapper / TinyMapper / Mapster / Mapperly alternative)

Topics

Resources

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages