SaveRateOpt refinement:
- only compile function when needed
- only run function during the saving period