If lag occur when merging chests using blueprint then i would suggest doing it while chests are empty. Scrip probably cannot be optimised much, it just find continous line of steel chests, create replacement wide/high chest, moves all items and deletes old steel chests.