bug 1041070 - fix O(N^2) runtime of tree update r=surkov