Update
With the release of UnreliableRemoteEvents, that have a payload limit of 900 bytes, this module has gained a pretty good usecase for ensuring max sizes! I’ll keep updating this module for the foreseeable future in the case of new datatypes & possible inconsistencies in calculating datatype sizes. If you find any bugs - please report them!
Introduction
Originally, this code was a part of the Packet Profiler plugin, but has now been separated into a separate resource to allow for usage in analytic environments. Additionally, this will make it easier to add requested or new unsupported types.
Functionality
The packet size counter calculates the size of remote packet data in bytes, given the packet data. It can calculate the byte size of a whole packet, but also individual data types. Examples:
-- Use the GetDataByteSize function to get the size of a single argument from a remote
PacketSizeCounter.GetDataByteSize(Value)
-- Use the GetPacketSize function to get the size of all arguments from a remote
PacketSizeCounter.GetPacketSize({
RunContext = "Client", -- Client or Server, remotes send different data based on context
RemoteType = "RemoteEvent", -- RemoteFunctions have an additional size offset
PacketData = {...} -- Array of remote packet data, supports most types
})
The full API can be found here:
Calculation
Roblox doesn’t offer any way to measure incoming packets, and so the only way to find out how large they are is by manually calculating the size based on input data.
There’s some incorrectness towards how some data types such as strings are calculated, but it becomes hard to fully replicate undocumented behavior.
The byte size for every supported data type has been measured as such:
- Send data through remotes and log the outcome with Roblox’s Network panel data
- Perform the measurement three times, and then average the result
- Do this measurement on three data amounts (10, 100, 1000), then perform linear regression to figure out the scale coefficient.
There exist edge-cases and differing behaviors of data types such as CFrames and strings, and as such the Rojo binary model was additionally used as reference. Through this, it can be found that CFrames have 24 special cases where axis-aligned CFrames are encoded as only 13 bytes instead of the usual 21. These edge-cases can be found here:
https://dom.rojo.space/binary.html#cframe
Installation
The resource’s source code can either be copied from the GitHub repository, or installed through Wally:
Contribution
You may look at how to contribute to the resource here:
https://github.com/Pyseph/RemotePacketSizeCounter/blob/main/CONTRIBUTING.md