Optimize dynamic_tree.