The iterator implementation (PathIterator) in the Trinidad RowKeySetTreeImpl class has the following problems:
1) It loops over the tree model even if the set is empty
2) It loops over the tree model even if the set contains no "default contained" nodes. "Default contained" nodes are "Expand All", "Select All", "Expand All Below", etc nodes.
For large tree models, unnecessary looping over the tree model can be expensive, since it can force the model to perform additional data fetches (beyond what is currently displayed in the view port on the client).
The attached patch provides a new iterator implementation called NodeIterator, which extends the current PathIterator and avoids unnecessary looping over the tree model. NodeIterator loops over the model only if it encounters "default contained" nodes in the set.