timeslice optimize code