Using Run Length Encoding (RLE) to Compress ROBLOX Terrain

Terrain-based ROBLOX IslandROBLOX released its high-performance terrain feature late in 2011, allowing users to create and play games significantly larger than anything previously seen on the platform. Many ROBLOX users have since taken advantage of terrain, particularly to facilitate expansive games with fast vehicles. Currently, the ROBLOX Content Team is pushing the feature further than ever before with a new game that procedurally generates destructible, cliff- and gold-ridden terrain each round (we’ll have more on that soon).

Terrain can be up to 2048 x 256 x 2048 studs in dimension, containing up to 16 million 4 x 4 x 4 terrain cells, with no graphics slow-down. One of the supporting techniques we use to make terrain so scalable and efficient is Run Length Encoding. Run Length Encoding makes the file sizes of terrain places a small fraction of what it would be with normal parts.

Run Length Encoding

Every published ROBLOX game is hosted on Roblox.com, so one of the keys to efficient terrain on our platform is saving the data in a cost-effective way. To that end, we use Run Length Encoding, or RLE. RLE is a method of storing a sequence of duplicates. Rather than store each duplicate item individually, RLE creates a count of the duplicates.

Let’s say we’re saving a small piece of terrain that consists of eight grass cells. You could store each grass cell individually – in this case, you would use five letters for each cell, for a total of 40 letters.

Grass Grass Grass Grass Grass Grass Grass Grass

Using RLE, we can store the small piece of terrain much more efficiently. Using only seven letters, we reduce the overhead by more than five times.

8xgrass

RLE doesn’t always save space because it’s dependent on there being a sequence of duplicates. For example, suppose you have alternating solid and empty spaces in a voxel grid. Again, you could store each cell individually.

solid empty solid empty solid empty

But using RLE would actually increase the data you’re storing by 12 characters, or about 40%.

1xsolid 1xempty 1xsolid 1xempty 1xsolid 1xempty

Duplicate Terrain Cells (Bottom view)

ROBLOX terrain is usually composed of a sequence of duplicates. As you can see in this screenshot of the bottom side of a common terrain formation, there are a lot of repeated cells.

A Practical Example

For a more practical example, consider two 15 x 15 x 15 structures, one made of standard ROBLOX parts and one built with terrain cells. Here’s a comparison of the amount of data stored with and without compression.

Regular ROBLOX parts Regular ROBLOX parts (Zipped) Terrain Terrain with RLE Terrain with RLE (Zipped)
8245 KB 83 KB 32768 KB 44 KB 3 KB

The unencoded, uncompressed terrain structure is actually more data intensive than the structure made with parts, but RLE and compression make the terrain structure much more efficient. Terrain with RLE and compression is 27 times smaller than compressed regular ROBLOX parts, 14 times smaller than terrain with RLE but no compression, and about 11,000 times smaller than standard terrain. ROBLOX uses zipped RLE terrain in practice.

Using these ratios, if you built a maximum-size terrain out of regular ROBLOX parts, the game file, even with compression, would already be around 380 MB.

We should note that much of the data for terrain is implicit; each cell’s position is implied by its terrain coordinate. That means we don’t need to save its position in the file. Parts, on the other hand, are physically simulated, so their starting position needs to be recorded and updated during the simulation.

Alternatives to RLE

There are many alternate compression techniques. Variations of RLE are commonly used for applications where speed to compress and speed to decompress are more important than average compression ratio. For example, Snappy, Google’s compression/decompression library, does not aim for maximum compression, but very high speeds and reasonable compression. At its core, Snappy uses RLE, with a few other techniques layered on top to further improve compression and decompression.

But standard RLE is a good fit for ROBLOX, and one of the key reasons why terrain, despite its expanse, doesn’t slow down the user experience.

222 thoughts on “Using Run Length Encoding (RLE) to Compress ROBLOX Terrain

  1. Yes, yes.. We all love the new Terrain features, just BRING BACK THE ACTUAL BASEPLATES UNDER CREATING AND RESETTING GAMES! I don’t care if you can easily remove the terrain ones with the elevation adjusters, you only made an inconvenience for us, and that’s what you’re against. If we wanted terrain baseplates, we’d just delete the brick ones and generate terrain. Possibly even terrain with 0% in the height bar. :/ Oh, and BRING BACK BUILD MODE!

  2. I wish there was a way for NBC robloxians to have more than one place becuase i wanna make a really cool terrain place but i dont want to get rid of my place i have now.

  3. Couldn’t you modify the RLE to detect whenever there is just one object in the sequence, and remove the “1x” and make the system recognize that? So instead of “1xgrass” it could just be “grass?” Just an idea, tell me any holes you find in it.

  4. This is really cool, if there is a way, could you make this be the way normal bricks on ROBLOX work as well? Because then we could build way more than what we can now (More as in bigger). If anyone knows if the admins can or can’t do this, send a message to cardgamechampion on ROBLOX, I really want to know this!

  5. TOO MUCH NOOBS ON SO-CALLED “EPIC” ASSASIN TEAM. I QUIT THAT STUPID GROUP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  6. I kinda like it but the terrain generator needs to also generate water too!

  7. I think this is something great to do with ROBLOX, to bad I won’t get to enjoy it since I can’t play now.

  8. This is kinda like Minecraft the Bricks and stuff You know The Wter is kinda the same to :l

  9. I bet they are going to but gold and silver in the terrain and turn every game into minecraft.

    • Next they’ll put working TVs into Minecraft and turn every server into real life… Just go have fun on Minecraft and leave ROBLOX alone.

  10. Cool. Snow would me next soon (Later or soon i wish like In November or somwhere about there for christmas)

  11. Really simple. All ROBLOX needs now, its High-performance snow, and Ill start useing it.

  12. I like the terrain, and don’t forget about the water… @Minecraft Fans who hate terrain.
    ROBLOX : Physics.
    MINECRAFT : Survival. Happy?

  13. Still does not fix the Water Update glitch for all the people who have been affected by it like me -.-

  14. “with no graphics slow-down”
    Lies.
    My computer is at the shop, so I’m using my old Gateway laptop running XP. The way ROBLOX sells their product, ROBLOX Studio should run just as fine on what I’m using now as it would on a brand new computer. However, when I’m generating even a small amount of terrain with my Gateway, it has tremendous slowdown to the point where I have to shut my computer down.

    • Mhm, they could notice that “…but not while generating terrain.”

      I think they mean when the terrain IS generated, it should not slow down. :P

    • duh,your running on whats called a low quallity, somwhere around only 200 dollar piece of junk. a pc on the other hand witha good graphics card will work fine, a 64 gaming pc with a oviously awesome graphics card can do anything.

  15. i got great ideas for roblox to help them and to make the a great place to get more people to come and some might be great some might be hmm think so think about the great ideas i got and send a message to me at my acc on roblox frog32145

  16. The terrain thing is pretty cool for Minecraft-based games. I also use the terrain water for my Cframed brick-based place.

  17. u now i didnt get a roblox till recently so yea im a noob and roblox is just getting harder i need help i hope someone replies

  18. This is what I been waiting for ages! Like I been waiting for Roblox to fix my water -_-

  19. I’m glad to say that this is a good idea. I loved the terrain feature when it came out; It saved me a lot of building and brought interesting new texture to Roblox. I’m glad to see it updated.

  20. Hmmmm… Most of that went over my head but seems pretty cool. And like minecraft

  21. Keep up the updating! ROBLOX is getting awesomer! I like the stamper tool because I can build more stuff! The water is working great unless it is below 0.2 studs but I make the game higher if I want to make stuff underground! Just one thing: Make scripting super easy so n00bs can make good places too! Ignore the I hate the new updates because I like them!

  22. Keep up the updating! ROBLOX is getting awesomer! I like the staper tool because I can build more stuff! The water is working great unless it is below 0.2 studs but I make the game higher if I want to make stuff underground! Just one thing: Make scripting super easy so n00bs can make good places too! Ignore the I hate the new updates because I like them!

  23. I miss the old roblox with the regular base plates this is like minecraft if I wanted this i would have just played minecraft