Automatically Optimizing Tree Traversal Algorithms