optimize saveHeights