optimize the write rolling condition