Currently, as of 5/23/23
, the Terrain:ReadVoxels()
API sets a mutex lock when any actor threads call it, so that only one thread at a time can get voxels from Workspace.Terrain
. This makes it impossible to read & serialize massive amounts of terrain in parallel through the use of actor instances.
If Roblox were to allow ReadVoxels()
to be called at the same time from multiple threads instead of mutex-locking (a write-lock only with no read-lock), it would allow developers to serialize huge amounts of terrain.
For example, let’s say I have an 8000x500x8000 piece of terrain that I want to serialize & manipulate:
Traditionally, we would have to read all of these voxels on a single thread. Assuming chunks of 400x400x400, that’s ~500 chunks of terrain to read! On a single thread that takes ~20 seconds to read (a long time)! However, by utilizing parallel threads (actors), we can split this into 4 threads making it ~125 chunks per thread. This would take less than half the time it takes on a single thread (~7 seconds).
Because of the mutex lock that Roblox sets on terrain, we are unable to utilize multiple threads to read different chunks of terrain at the same time, limiting what we can do with terrain.