Efficiently encode trees into the url string.