Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SWQXDBA opened this issue Mar 1, 2024 · 6 comments · Fixed by #69
Closed

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

SWQXDBA opened this issue Mar 1, 2024 · 6 comments · Fixed by #69
Labels

Comments

@SWQXDBA
Copy link

SWQXDBA commented Mar 1, 2024

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

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

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

@linpeilie
Copy link
Owner

aop的切面是什么呢

@SWQXDBA
Copy link
Author

SWQXDBA commented Mar 3, 2024

aop的切面是什么呢

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

@linpeilie
Copy link
Owner

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

@linpeilie linpeilie linked a pull request Mar 15, 2024 that will close this issue
@linpeilie
Copy link
Owner

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

Copy link

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

@github-actions github-actions bot added the stale label Apr 15, 2024
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants