Fix infinite undo stack
It might be possible that it was the reason of the slowdown bug, but it needs to be checked.
BUG:408255 CCBUG:408133