Many devs see slow API responses and blame SQL, not realizing the slowdown is Mapper.
⚠ The Problem
AutoMapper uses reflection for complex object graphs.
Under load → becomes slow.
✔ Life-Saver Solution
Switch to compiled mapping:
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<User, UserDto>().ConvertUsing(src =>
new UserDto(src.Id, src.Name));
});
or write your own mapping:
public UserDto Map(User u) =>
new(u.Id, u.Name);
⚡ Result
-
Up to 10× faster mapping
-
Massive CPU drop
