4 ms·
Automapper generates all mappings at runtime with reflection. Mapperly in contrast uses roslyn based source generators and generates all mapping code at compile
by latonz 4y ago
Automapper generates all mappings at runtime with reflection.
Mapperly in contrast uses roslyn based source generators and generates all mapping code at compile time. This leads to improved runtime performance with less allocations [1]. Since no reflection is used at runtime, the generated code is completely trimming save and AOT friendly.
[1] https://github.com/mjebrahimi/Benchmark.netCoreMappers https://github.com/mjebrahimi/Benchmark.netCoreMappers
- orra 4y agoThose are pretty compelling advantages. Thanks for sharing.
- mpawelski 4y agoAnd what's the advantages over Mapster? (haven't used it yet, but I see it's mentioned often as a "better Automapper" alternative)
- CommonGuy 4y agoNever used Mapster myself, but as far as I can see, Mapster does not provide a Roslyn based source generator. By default, it seems to create mappings at runtime (if not using the Mapster Tool to create mappings at build time).
- danbruc 4y agoEven though AutoMapper of course uses reflection to construct mappings, executing mappings does not involve reflection if not necessary. AutoMapper builds expression trees, compiles them on first use, and uses the resulting function to perform the mapping. If your mapping involves things only accessible through reflection, then the compiled mapping function will of course still have to rely on reflection.