Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-5900

Performance of ConfiguredInheritance.NodeDepthComparator is really slow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 4.5.21
    • rendering

      In this comparator we do a node iteration to calculate the position in the tree. Which seems to be quite slow. It seems to be used when there is inheritance involved which we use quite a lot but not to an extreme.

      Page generation can be up to 3 times slower because of this code. Which makes the site return 500 errors during a activation. At that time the full cache is flushed in our site because of the complexity of our dependencies.

      Is there no smarter, faster way to calculate the index?

      Copied the code that causes it.

      NodeDepthComparator
                      public int compare(Node lhs, Node rhs) {
      			try {
      				if (lhs.getDepth() != rhs.getDepth())
      					return lhs.getDepth() - rhs.getDepth();
      
      				return getSiblingIndex(lhs) - getSiblingIndex(rhs);
      			} catch (RepositoryException e) {
      				throw new RuntimeRepositoryException(e);
      			}
      		}
      
      		private int getSiblingIndex(Node node) throws RepositoryException {
      			if (node.getDepth() == 0) {
      				return 0;
      			}
      			int index = 0;
      			NodeIterator nodes = node.getParent().getNodes();
      			while (nodes.hasNext()) {
      				if (NodeUtil.isSame(node, nodes.nextNode())) {
      					return index;
      				}
      				index++;
      			}
      			return -1;
      		}
      

        Acceptance criteria

              Unassigned Unassigned
              dwartel David Wartel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD