threading: optimize the flags() method to not descend into the rather expensive path
threading: delay tree pruning until after the event loop is reached again

This is not really a proper fix (servers who don't do VANISHED will still make
the client suffer), but it's a step in the right direction, and also something
much, much more effective than trying a special-case branch for removal of leaf
nodes.

The idea here is to cut the total amount of times pruneTree()/layoutChanged() is
called in total. I'm worried about using non-zero delay due to the unit tests...

refs #642