linpeilie / mapstruct-plus

MapStruct Plus is an enhancement to the MapStruct framework. It can automatically generate the transformation operation between two classes through an annotation, omitting the operation of defining the interface of MapStruct, makes Java type conversion easy and elegant.
https://mapstruct.plus/
Apache License 2.0
263 stars 20 forks source link

spring+aop场景下性能很低 #67

Closed SWQXDBA closed 5 months ago

SWQXDBA commented 7 months ago

线上压测发现QPS很低 发现瓶颈出现在了mapstruct-plus上。 image

image 在调用集合转换时 spring会每次去容器中搜索实现类 调用堆栈大概是这样的。 image

怀疑是动态代理+@Lazy时 spring每次取实现类的时候要到整个容器中进行搜索。 每次都会走JdkDynamicAopProxy的invoke方法,然后调用 target = targetSource.getTarget(); 我觉得问题在于ContextAnnotationAutowireCandidateResolver在buildLazyResolutionProxy方法中提供的TargetSource没有缓存,每次都会去整个Spring容器中搜索。 是否有办法规避这个问题?

linpeilie commented 7 months ago

aop的切面是什么呢

SWQXDBA commented 7 months ago

aop的切面是什么呢

是一个日志的切面,我试验后发现跟切面没啥关系。主要是@Lazy的问题。 后面我切换到了非spring模式。发现会有另一个性能问题:大概是在拷贝集合的时候,每次拷贝会去调用Mappers.getmapper这种方法取获取对应的mapper对象,这个操作在循环中性能也很低。 也就是说 在拷贝集合的时候 在拷贝每个元素时都要根据这个元素的类型去检索对应的mapper,而并非检索一次后用那个mapper对集合中的每个元素进行拷贝。这样会产生很多查找mapper本身的开销(尽管是HashMap中获取 复杂度不高,但是相比拷贝本身而言它的额外开销还是太大了)

linpeilie commented 7 months ago

等我空的时候看下, 如果是因为这个原因就换一下实现,这个好解决

linpeilie commented 6 months ago

可以更新 1.4.0-R1 版本,试一下

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 5 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.