Hi guys,

I found that my application waste a lot of time in code like following:

Stack trace 1:
        at java.lang.System.identityHashCode(Native Method)
        at
com.google.common.collect.MapMaker$Strength$1.hash(MapMaker.java:346)
        at
com.google.common.collect.MapMaker$StrategyImpl.hashKey(MapMaker.java:528)
        at
com.google.common.collect.CustomConcurrentHashMap$Impl.hash(CustomConcurrentHashMap.java:637)
        at
com.google.common.collect.CustomConcurrentHashMap$Impl.get(CustomConcurrentHashMap.java:1330)
        at
com.tc.object.ClientObjectManagerImpl.basicLookup(ClientObjectManagerImpl.java:913)
        at
com.tc.object.ClientObjectManagerImpl.lookupExistingOrNull(ClientObjectManagerImpl.java:390)
        at
com.tc.object.bytecode.ManagerImpl.lookupExistingOrNull(ManagerImpl.java:415)
        at
com.tc.object.bytecode.ManagerImpl.lookupExistingOrNull(ManagerImpl.java:71)
        at
com.tc.object.bytecode.ManagerUtil.lookupExistingOrNull(ManagerUtil.java:314)
        at java.util.Arrays.sort(Arrays.java:1078)
        at java.util.Collections.sort(Collections.java:117)

Stack trace 2:
        at java.lang.Object.hashCode(Native Method)
        at
com.tc.object.bytecode.hook.impl.ArrayManager.hash(ArrayManager.java:593)
        at
com.tc.object.bytecode.hook.impl.ArrayManager.getObject(ArrayManager.java:78)
        at
com.tc.object.bytecode.hook.impl.ArrayManager.objectArrayChanged(ArrayManager.java:154)
        at
com.tc.object.bytecode.ManagerUtil.objectArrayChanged(ManagerUtil.java:995)
        at java.util.AbstractCollection.toArray(AbstractCollection.java:171)
        at java.util.regex.Pattern.split(Pattern.java:1027)
        at java.lang.String.split(String.java:2292)

I found that it is a known long standing issue:
- http://forums.terracotta.org/forums/posts/list/4379.page
- https://jira.terracotta.org/jira/browse/CDV-788

As I can see from sources both ClientObjectManagerImpl and ArrayManager use
some sort of synchronization inside.
I would like to suggest some simple optimizations which doesn't require
complex changes in code.
Before calculating hashCode and making any lookups with synchronization we
can make simple checks which in many cases can avoid expensive operations.
These simple checks are:
1. Clustered array should contains clustered elements. So we can check
whether its first element is clustered or not.
Checking whether element is clustered or not costs almost nothing. Also
spare arrays (arrays with null elements) are rather seldom, so in many
cases we will avoid synchronization.
2. We can check whether element type is instrumented or not. If it is not
instrumented then there is no need to make any synchronization.

Guys, what are you thinking about these ideas? Is it worth to implement
them?

With best regards,
Michael Mikhulya
_______________________________________________
tc-dev mailing list
tc-dev@lists.terracotta.org
http://lists.terracotta.org/mailman/listinfo/tc-dev

Reply via email to