NetRay - High-Performance Roblox Networking Library

I used --!strict initially, but when I did it in VScode, it said no issues, but in Roblox I would get a bunch, so I removed the --!strict for now

This is Odd. I am not sure why, for it doesn’t show up

Thats because VS Code doesnt natively support Luau. This lack of native support leads to inconsistencies and disagreements between VS Code’s standard Lua analysis and Roblox’s Luau implementation. It would best for you to annotate the code in roblox and make sure no type errors arise.

Edit: I have all of the roblox studio beta features enabled to adjust, just besides the new type solver.

1 Like

Yeah, I switched from Vscode because it just gave me problems I only use it for the github repo. I removed strict from the scripts already and was able to fix the issues

I have the incremental typechecker and autocompletion on; maybe that’s the issue?

edit: I enabled the new luau type solver and it just gave me 500+ warnings

This may be, try changing it and maybe all of the type errors will be visible for you too

Edit: Thanks for helping me reach my goal:
image

2 Likes

I disabled and this is my script analysis now.
very odd

edit:
Try either running the game once or saving i.t Might fix?

Try removing the NetRay module and adding it again into the studio place youre in

1 Like

I only get the extra warnings when I put --!strict on the scripts I am guessing it’s showing you it all?

Literally i get warnings from almost all of the modules within the NetRay module and from the NetRay module itself. (ignore the highlighted type error, and the one on the bottom)
image

1 Like

I think I know why now

image

Do you have this beta feature enabled? If so, turn it off.

without it on

I will be making all the scripts strict or most in the future

edit: the 3 warnings and expected and know, right now the JSON and EfficientTable types aren’t being used anyways since I changed the logic

2 Likes

Yeah please do! Its a must in my workspace. Thanks for helping me out!

1 Like

No Problem, I’ll be focusing on the strict issues for the next update

1 Like

I created a flowchart of the Dynamic Senders logic if you want to understand how it works.

I will update this in the future, as this is not everything but a simplified explanation

Is there a way to make this work with Tuples?

local _ray = require(game:WaitForChild("ReplicatedStorage", 500):WaitForChild("NetRay", 500))

_ray:GetEvent("_"):OnEvent(function(...)
	print(...)
end)
local _ray = require(game:GetService("ReplicatedStorage").NetRay)

_ray:RegisterEvent("_"):FireAllClients("hi", 1, workspace)

Also, this doesn’t work when the client started before the server, for example, getting the event on ReplicatedFirst and then firing from server would cause the client to not get any data.

1 Like

This is because if the server isn’t set up the event won’t exist etc, You can yield it using task.wait() which should solve your issue or allow the server to set up (this would be only for the first player to join)

Tuples should already work with NetRay

  1. Analysis: When the serializer encounters a table, the analyzeTable function determines if it’s a candidate for HomogeneousArray or if it should be treated as a generic Dictionary.
  2. Homogeneous Array Optimization: If your tuple happens to be:
  • Non-empty

  • A dense array (keys 1, 2, 3… N with no gaps)

  • Contains elements of the exact same, simple, supported type (like all NumberU8 or all String (<=255 bytes) or all Vector3S16, etc. - crucially not mixed types, and excluding nested tables, Instances, Buffers, Binaries, or Nils).
    Then, it will be serialized using the efficient HomogeneousArray format (TypeCode 0xD0). This writes the element type code once, the array length, and then just the data for each element consecutively.

  1. Dictionary Fallback: If your tuple/array does not meet the strict homogeneous criteria (e.g., it contains mixed types like {true, “message”, 123}, or complex types like Instances, or is empty or sparse), analyzeTable will classify it as a Dictionary (TypeCode 0xD1).
  • In this case, the serializer iterates through the table using pairs (which for an array includes keys 1, 2, 3…). It then recursively serializes each key (the number 1, 2, 3…) and each value individually.

  • The deserializer reads the key-value pairs and reconstructs the original array table.

  • It uses a highly efficient Homogeneous Array format if all elements are of the same simple type.

  • It falls back to a less efficient (but still functional) Dictionary format for arrays with mixed types or unsupported element types, serializing the numeric indices as keys.

I tried to do that but it just prints “hi”, since I use an effect system that constantly fires to all clients, I need to send all types of data, this including Instances all the way to Vector. Keep in mind I don’t send in a table, I just need it as individual arguments, as shown in the second snippet in my original reply.

1 Like

Benchmarks Results

  • No CPU usage
  • No FPS drops or is even effected
  • Ping is not effected

Bools

  • Netray Peforms the best out of all Networking modules in bools with blink being a close 2nd the rest all got around 3x the network sent compared to the 2

StructOfNumbers

  • Blink performed the best (as expected, and it’s fully predefined and an IDL compiler )
  • NetRay performed the second best by FAR, with only Blink being first

Test place
Benchmark (2).rbxl (240.9 KB)

Edit:
Editing the max batch size resulted in a Huge performance improvement! and fixed benchmark place for netray v1.1.0 without throttling

Have you tried
_ray:RegisterEvent("_"):FireAllClients({"hi", 1, workspace})

I see what you mean now. When I tested it printed it as a table, and you don’t want that?

1 Like

This worked and I just did table.unpack(...) on client.

1 Like

One more question, is it possible to get an Event from another script? I wanna have a single script register an event but have other scripts either get the event or fire the event without talking to the original script that registered the event.

1 Like