Async chunk I/O #6560
Labels
BC break
Breaks API compatibility
Category: Core
Related to internal functionality
Opinions Wanted
Request for comments & opinions from the community
Performance
Type: Enhancement
Contributes features or other improvements to PocketMine-MP
Problem description
I attempted to implement async chunk I/O in PM as far back as 2017 in #1895.
However, this PR failed for a variety of reasons, including complexity, bugs, and huge impact to API (and therefore plugins).
Async chunk I/O is no longer as in-demand as it was a few years ago, due to massive improvements in server disk hardware (NVMe and the like), but it would still be desirable if done right. However, the advantage has to be weighed against the cost of transmitting the data between threads, since serialization & deserialization for passing stuff between threads can have significant costs of its own.
Proposed solution
The biggest obstacle is that, in order to avoid major sweeping API breaks for a multitude of functions, we'd need to support both sync and async chunk I/O, because many API methods directly used by plugins currently auto-load chunks synchronously, and there isn't a clear way to avoid significant increases in complexity for tasks as simple as
getBlock()
unless synchronous chunk loading is supported.(However, it's worth mentioning that plugins seem to have adapted fairly well to the use of Promises for generation, and major advances have been made overall since 2018, so maybe this might be easier in 2024 than back then.)
#1895 was abandoned because I'd designed it in such a way that made it impossible to support both sync and async chunk loading. A better solution might involve using ThreadSafe objects to create waitable Futures or something of that nature. That way, stuff that doesn't require sync chunk loading (like players) can request & wait, while stuff that does need sync loading could wait on the future (which would block the main thread as I/O currently does).
Alternative solutions that don't require API changes
The text was updated successfully, but these errors were encountered: