# Time-slicing:freeze-frames, lag spikes Time-slicing reduces the spikes in poor performance or individual "freeze-frames" which occur due to many processes running in one particular frame - for example, a frame in which a large area of the world is loaded, or where many AI agents make decisions. Time-slicing smooths out the spike in poor performance so it's less visible. Time-slicing does *not* fix performance issues which are consistent across frames - if the game is always slow and laggy, time-slicing won't fix it. ```gdscript class TimeSlicer: const TIME_SLICE_MS: 50 # We'll say that _process() can only run for 50 milliseconds, or just under 1/60th of a second. var index = 0 func _process(_delta): var start_time = Time.get_ticks_msec() # Save the time we began processing. var start_index = index # Save the first index we processed. while (Time.get_ticks_msec() - start_time < TIME_SLICE_MS): # Go until we run out of time, or... objects[index].process(_delta) index = wrapi(index+1, 0, objects.size()) if index == start_index: # ... until we've processed all the objects. break ``` The shorter the time-frame you give TimeSlicer, the zippier each frame will be, but the longer it will take in real-time to process all your objects. Sometimes this is fine, especially when you're working on behind-the-scenes stuff the player can't see, or preparing something to use later.