-
Notifications
You must be signed in to change notification settings - Fork 14
Description
So, i switched from ZenLib to ZenKit some months ago for my renderer.
Now in ZenLib, VDF/MOD archives were loaded with PhysFS, which apparently does not keep its archive files in memory and instead keeps only handles to the files inside the archives. When loading a single asset file, the correct archive is opened and the content is read, after which the archive is closed again, every time.
Now in ZenKit, all archives are permanently kept in memory. For grahics mods coming with somewhat big textures (like GRM, which has 1k/2k textures), this essentially multiplies the memory usage during load time by an order of magnitude or more. This makes ZenKit essentially unusable for me for a 32bit target binary. Now, the reason why i want to be able to run a 32bit binary is that im interested in keeping the possibility open of hooking my renderer into the original game (not really on the table yet but still).
In my renderer, i have a certain commit where i added ZenKit without removing ZenLib, that works with both libraries using a simple flag, so i can make an easy comparison of memory usage during loadtime between both libraries.
ZenRen 32bit+LAA, loading GRM WorldMesh, w ZenLib:

322 MB (Commit)
ZenRen 32bit+LAA, loading GRM Worldmesh, w ZenKit:

3512 MB (Commit)
So, the virtual memory space is 10 times bigger during load (close to half of that being memory mapped VDFs).
Note: 32 and 64bit binaries are not comparable under Windows, since for 64bit all VRAM allocation are part of commited memory space, which makes 64bit binaries always commit much more than 32bit for applications with lots of VRAM buffers.
I have to restrict my test to WorldMesh loading only, since loading with ZenKit actually crashes due to OOM (std::bad_alloc) if i try to also load VOBs. This is because the commited memory then reaches 3,8-3,9 GB, at which point any further substantial vector allocations fail, since 32bit+LAA applications have a max virtual memory space of 4 GB.
I have tried disabling ZK_ENABLE_MMAP, which does disable mmaped memory, but does not change the problem, because then all VDFs are just loaded as byte arrays, but they are still kept in memory, so commited memory basically does not change.
So my question is, would it be feasable to add a flag to ZenKit that keeps VDFs out of memory unless a file from that VDF must be actually loaded?
I could also try to implement this, but i am not very good at C++, so i might struggle with that.