Minestom / Hephaistos

NBT & Anvil save format library
MIT License
57 stars 10 forks source link

Too much memory used in simple read-write scenarii #10

Closed jglrxavpok closed 1 year ago

jglrxavpok commented 3 years ago

See https://github.com/Minestom/Minestom/issues/422

Minestom uses ChunkColumn only for reading and writing to storage. Following my discussion with @TheMode on Discord, an API to stream chunk contents instead of caching them could be introduced to reduce memory allocations.

Below is a memory flame graph following chunk loading with the AnvilLoader of Minestom image

jglrxavpok commented 2 years ago

List of elements to implement:

Both Minestom and the internals of Hephaistos should use the streaming API. (Will be updated when new things are found)

Streaming needs to provide both a way to read and a way to write (Minestom will need it). Which features you want to use need to be explicit (to avoid reading stuff we don't care about, and simplify code). Depending on the implementation, this can be an abstract class with empty default implementations, or a bit mask.

Read

Per-chunk data

Features used by Minestom:

Features represented with the current Hephaistos ChunkColumn/ChunkSection API

New features:

Per-section data

Features used by Minestom:

Write

Per-chunk data

Features used by Minestom:

Features represented with the current Hephaistos ChunkColumn/ChunkSection API

New features:

Per-section data

Features used by Minestom:

jglrxavpok commented 2 years ago

Outside of the """new""" entities/ region files, all readers are ready.

jglrxavpok commented 1 year ago

Was done in commit 6b386efa4f610f8abb7917326cd88f1b22ab76d4