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

improve performance of projection instantiation #1873

Merged

Conversation

stsypanov
Copy link
Contributor

I've run into poor performance of projection creation with Spring Data JPA. Using async profiler I've measured 10 hottest methods for my particular case:

          ns  percent  samples  top
  ----------  -------  -------  ---
  1719680599   17.75%     1719  org.springframework.util.ConcurrentReferenceHashMap.calculateShift
  1075919136   11.11%     1076  org.springframework.util.ConcurrentReferenceHashMap.<init>
   995216304   10.27%      995  org.springframework.aop.framework.JdkDynamicAopProxy.findDefinedEqualsAndHashCodeMethods
   549197362    5.67%      549  java.util.LinkedList.toArray
   505954398    5.22%      506  java.lang.String.regionMatches
   441133709    4.55%      441  java.util.concurrent.ConcurrentHashMap.get
   187450280    1.93%      187  /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
   166974974    1.72%      167  java.util.ArrayList$Itr.<init>
   160991064    1.66%      161  org.springframework.aop.framework.JdkDynamicAopProxy.getProxy
   155019312    1.60%      155  org.apache.logging.slf4j.SLF4JLogger.isEnabledFor

The simple way to slightly improve this is to get rid of LinkedList in org.springframework.aop.framework.AdvisedSupport and use plain constructor call in org.springframework.util.ConcurrentReferenceHashMap.<init>.

LinkedList::toArray is obviously slower than ArrayList::toArray.

In ConcurrentReferenceHashMap method createReferenceArray can use plain constructor to instantiate array which yields equal performance when compiled with C2 but 3 times better performance in interpreter mode.

@jhoeller jhoeller merged commit 6d6aa72 into spring-projects:master Jul 9, 2018
@jhoeller
Copy link
Contributor

jhoeller commented Jul 9, 2018

Thanks for pointing those out! I'll backport them to 5.0.8 in my next round of polishing there as well.

@stsypanov
Copy link
Contributor Author

@jhoeller I've spotted a lot of usages of LinkedList in code of Spring Framework. Is it acceptable to create a separate pull request to replace them all with ArrayList/ArrayDeque?

@jhoeller
Copy link
Contributor

Instead of a straight find-and-replace PR, I'd prefer reviewing those LinkedList usage spots my side, having a look at the context around them and potentially revisiting the overall state arrangement in the affected classes. Could you create a JIRA ticket for this please, I'm happy to pick it up for 5.1 RC1 still: https://jira.spring.io/browse/SPR

@stsypanov
Copy link
Contributor Author

Ticket created: https://jira.spring.io/browse/SPR-17037

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

Successfully merging this pull request may close these issues.

None yet

2 participants