There are some good concepts in here that developers should know, well done! Never considered table preallocation before, good to know.
If I could mention one more thing for this post, it’s some general notes about networking. Roblox throttles both network receive and send at 50 kb/s, going beyond this (e.g. having too many moving parts being replicated to the clients at once) will make the engine attempt to throttle the network traffic back down to 50 kb/s which leads to “slow and laggy gameplay”.
Here are common pointers to avoid going beyond this softlimit:
- For RemoteEvents:
- Compress data as much as you can, here’s a very good post by @PysephDEV that talks datatypes and their equivalent byte size.
- Ratelimit the data you send, only send data when it is necessary (e.g. letting clientside interpolation do a huge chunk of the work)
- Batch the data you send, this is what networking libraries do (as mentioned in the post)
- For physics, you can consider setting PhysicsSteppingMethod to adaptive. In short, Roblox’s physics are calculated at 240Hz (240 times per second) by default, however, setting your physics stepping to adaptive will allow the engine to dynamically lower the rate of physics calculations if deemed necessary. The rates can only either be: 60Hz, 120Hz, and 240Hz.