Open NielsPichon opened 1 month ago
This issue has been discussed in #14 , and the proposal was a compromise between the current behavior of keeping everything forever and your suggestion of never storing the parsed RegionFile
object: allow the client to choose what and when to keep regions by adding a cache
boolean argument when loading and an .uncache()
method to (manually) unload regions.
To make this approach work with your example, you could add regions.uncache(region_coords)
(or region.uncache()
if it's feasible to implement that) in the end of the loop.
Additionally we could implement a cache
attribute to Regions
, if set to False
prior to the loop the direct dictionary access in it would not store the loaded region object in the dictionary, as you requested.
In any case, I suggest we move the discussion of how to better implement this is in #14, as I've already outline a few approaches and challenges
Absolutely. This would work great as a solution. Thanks 👍
Issue
As of now, the region files are lazy loaded, but they never actually get offloaded, which may lead to Out Of Memory exceptions on smaller machines or for larger maps.
Not sure whether this affects many people but I thought it'd be a nice to have.
Expected behaviour
Regions are offloaded after they are queried, or maybe after N regions are loaded, the N-th + 1 pushed the oldest one out of memory.
implementation ideas
Instead of using a dict for storing dimensions' Regions, there could be a class which inherits from Dict but which
__getitem__
is overridden and returns an instance of a realized RegionFile without storing it, or something like that, essentially always keeping the LazyLoadFileMap version of the region in the dict rather than the RegionFile itself.To reproduce
You should see the memory usage grow. like so: