Introduce WriteTree2 as a more performant replacement of WriteTree

Fixes #238.