public TraceNode compact() {
        if (isLeaf()) {
            return this;
        }
        List<TraceNode> tmp = this.children;
        this.children = new ArrayList<>();
        for (TraceNode child : tmp) {
            child.compact();
            if (child.isEmpty()) {
                // ignore
            } else if (child.isLeaf()) {
                addChild(child);
            } else if (strict == child.strict) {
                addChildren(child.children);
            } else if (child.getNumChildren() == 1) {
                TraceNode grandChild = child.getChild(0);
                if (grandChild.isEmpty()) {
                    // ignore
                } else if (grandChild.isLeaf() || strict != grandChild.strict) {
                    addChild(grandChild);
                } else {
                    addChildren(grandChild.children);
                }
            } else {
                addChild(child);
            }
        }
        return this;
    }
Compact this tree. This will reduce the height of this tree as much as possible without removing information
stored in it.

@return This, to allow chaining.
messagebus/src/main/java/com/yahoo/messagebus/TraceNode.java