wrello/plums

Replicate table changes from server to client in Roblox

plums icon

Plums

API: wrello.github.io/Plums/

⚠️Currently in beta. Not recommended for use in production.⚠️

  • Supports nested plums
  • Includes server-side plum events
  • Propagates value changed events from sub-tables
  • Supports Event:Observe() to collect prior values
  • Uses Squash to compress overhead plum data

Install

Roblox model: https://create.roblox.com/store/asset/112997442485158 Wally: Pesde:

Quick Start

Initialize server & client first:

-- Server
local Plums = require(game.ReplicatedStorage.Plums.PlumsServer)
Plums:Init()
-- Client
local Plums = require(game.ReplicatedStorage.Plums.PlumsClient)
Plums:Init()

Then create a plum:

-- Server
local playerPlum = Plums.new("Player", {
  Coins = 0
}):AddAllClients():EnableAutoAddClient()

playerPlum:SetValue({"Coins"}, 5)

And listen to its changes:

-- Client
Plums.PlumReceived("Player"):Observe(function(playerPlum)
  print("Player plum received:", playerPlum.Data)

  playerPlum.ValueChanged({"Coins"}):Observe(function(newVal, oldVal)
    print("Coins:", newVal)
  end)
end)

Comparing With Replica

loleris's ReplicaService (now Replica) was the inspiration for this library, here are some comparisons with Replica...

Speed

Replica resolves a single path in its table modification methods:

local pointer = self.Data
for i = 1, #path - 1 do
  pointer = pointer[path[i]]
end
pointer[path[#path]] = value

Plums performs additional path resolutions for:

  • nested plums
  • server-side event listeners
  • propagation of value-change events through nested structures

This can cause table modification methods to be up to ~10× slower depending on how complex the plum is. This speed tradeoff should not be noticable in practice (e.g. 10,000 table modification calls on a deeply nested plum with lots of event listeners takes 0.05 seconds).

Packet Size

Results with a small table:

Packet TypeReplica SizePlum Size (compressed with Squash)
Initial object send88 bytes82 bytes
Method replication63 bytes62 bytes