1. Adjust insertion last task process time to be the current time.
This makes fresh inserts to be scheduled fairly with current
inserts.
2. Always attempt to watch global first task
This should try to prevent multiple scheduler threads from
waiting on the same task. If the global first task is our task,
then we can avoid retrying for the next task.
3. Correctly set runner state to TASKS when parsing intermediate
tasks. This will prevent the runner from being interrupted
by notifyTasks.
The old region scheduler had a few problems:
1. Inability to process intermediate tasks (chunk/packets) leading
to higher than Paper/Vanilla latencies for task processing
2. Thread swapping: scheduled tasks had no thread preference, which
lead to them swapping threads which may not be cache efficient
The new scheduler solves both of these issues. The new scheduler
can process intermediate tasks, and combined with the new packet
scheduler this allows packets to be processed at low latency
provided that the scheduler threads are idle or waiting.
The new scheduler will only move a scheduled tick/task to another
scheduling thread provided that its scheduled start is missed by
a specified time (for now, 2ms). This should ensure that thread
swapping only occurs to meet scheduling deadlines.
We cannot guarantee that the current region owns the chunk
associated with the ChunkData. As a result, more than 1 region
may write to the field.
Additionally, we did not include any logic to adjust the field during
a region merge or split - which would leave invalid data in the field.
As a result, the nearbyPlayers data retrieved from the ChunkData
was possibly invalid which may have lead to entity tracker desync
problems.
Fixes https://github.com/PaperMC/Folia/issues/317