Fix performance issue for unfold