You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Thomas Mueller (JIRA)" <ji...@apache.org> on 2013/10/30 15:33:36 UTC

[jira] [Commented] (OAK-1130) Performance issues with MutableTree

    [ https://issues.apache.org/jira/browse/OAK-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13809152#comment-13809152 ] 

Thomas Mueller commented on OAK-1130:
-------------------------------------

Proposed patch. Changes in the AbstractRoot: use ImmutableTree instead of mutable. Changes in AstElement: cache the used last tree.
{code}
Index: src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
===================================================================
--- src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java	(revision 1537076)
+++ src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java	(working copy)
@@ -329,7 +329,11 @@
             @Override
             protected ExecutionContext getExecutionContext() {
                 NodeState rootState = AbstractRoot.this.getRootState();
-                return new ExecutionContext(rootState, rootTree, getIndexProvider(rootState));
+                Context c = securityProvider.getConfiguration(AuthorizationConfiguration.class).getContext();
+                PermissionProvider pp = permissionProvider.get();
+                SecureNodeState s = new SecureNodeState(rootState, pp, c);
+                ImmutableTree t = new ImmutableTree(s);
+                return new ExecutionContext(rootState, t, getIndexProvider(rootState));
             }
 
             private QueryIndexProvider getIndexProvider(NodeState rootState) {
Index: src/main/java/org/apache/jackrabbit/oak/query/ast/AstElement.java
===================================================================
--- src/main/java/org/apache/jackrabbit/oak/query/ast/AstElement.java	(revision 1537076)
+++ src/main/java/org/apache/jackrabbit/oak/query/ast/AstElement.java	(working copy)
@@ -30,6 +30,8 @@
 abstract class AstElement {
 
     protected QueryImpl query;
+    private Tree lastTree;
+    private String lastPath;
 
     abstract boolean accept(AstVisitor v);
 
@@ -123,7 +125,11 @@
     }
 
     protected Tree getTree(String path) {
-        return query.getTree(path);
+        if (lastPath == null || !path.equals(lastPath)) {
+            lastTree = query.getTree(path);
+            lastPath = path;
+        }
+        return lastTree;
     }
 
 }
{code}

> Performance issues with MutableTree
> -----------------------------------
>
>                 Key: OAK-1130
>                 URL: https://issues.apache.org/jira/browse/OAK-1130
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: core, query
>            Reporter: Thomas Mueller
>
> Benchmarks show that simple queries are slower in Oak than in Jackrabbit 2.x. The profiling data shows that most time is spent in the MemoryNodeBuilder (see below), called from MutableTree, even thought the query engine internally doesn't need mutable trees.
> It would be nice if creating a tree is faster (MemoryNodeBuilder, MutableTree and related). Many components would benefit from that. Unfortunately, the code is quite complex (meaning, I don't understand it).
> I found two alternatives to speed up queries:
> * Not use MutableTree within the query engine, but instead use ImmutableTree. This gave a small performance boost (maybe 15%)
> * Cache trees in the query engine, to avoid creating the same tree multiple times. This gave a speedup of about 50% (twice as fast) for some tests.
> Package summary and top stack trace as reported by the profiler.
> {code}
> summary:
> 65%: org.apache.jackrabbit.oak.plugins.memory
> 9%: org.apache.jackrabbit.oak.plugins.segment
> 4%: org.apache.jackrabbit.oak.jcr.session.operation
> 3%: org.apache.jackrabbit.oak.query
> 2%: com.google.common.collect
> 2%: org.apache.jackrabbit.oak.namepath
> 341/3234 (10%):
> org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder$ConnectedHead.getCurrentNodeState(MemoryNodeBuilder.java:601)
> org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder$UnconnectedHead.update(MemoryNodeBuilder.java:535)
> org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder.head(MemoryNodeBuilder.java:152)
> org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder.exists(MemoryNodeBuilder.java:254)
> org.apache.jackrabbit.oak.core.SecureNodeBuilder.getChildNode(SecureNodeBuilder.java:299)
> org.apache.jackrabbit.oak.core.MutableTree.<init>(MutableTree.java:76)
> org.apache.jackrabbit.oak.core.MutableTree.createChild(MutableTree.java:86)
> org.apache.jackrabbit.oak.core.MutableTree.getChild(MutableTree.java:222)
> org.apache.jackrabbit.oak.util.TreeUtil.getTree(TreeUtil.java:169)
> org.apache.jackrabbit.oak.query.QueryImpl.getTree(QueryImpl.java:604)
> org.apache.jackrabbit.oak.query.ast.AstElement.getTree(AstElement.java:126)
> org.apache.jackrabbit.oak.query.ast.SelectorImpl.currentTree(SelectorImpl.java:351)
> {code}
> Some benchmark results for the oak-run SimpleSearchTest with combination of changes (patch will follow). Just "N", meaning number of iterations within 10 seconds (higher is better), using Oak-Tar:
> * old (mutable tree, no cache): 36
> * immutable tree only: 42
> * cache only: 65
> * cache+immutable: 76



--
This message was sent by Atlassian JIRA
(v6.1#6144)