How many connections till decreased performance?

I’m working on a server–client replication system and I’m concerned about potential performance issues with CollectionService connections.

Here’s the setup:

  • Each part will have a CollectionService:GetInstanceAddedSignal() connection linked to its replication ID, in cases where the part isn’t currently loaded due to StreamingEnabled.
  • Once the part is streamed in, that connection is destroyed.

My concern is: if I end up with around 1,000 connections at once, would that have a noticeable performance impact?

Thanks

Essentially, this method returns an RBXScriptSignal which internally stores a table of your listeners. When the signal is fired, the code simply iterates through all the listeners and they are called.

But I’m asking if this will have any performance impact?

I don’t think the connections in of themselves will have that much of a performance issue (correct me if I’m wrong more knowledgeable people), but rather the performance impact would depend on how much resources are being taken up when running the code inside of the connections. So a few simple lines of code in the 1,000 connections won’t really have much of an impact compared to the thousands of lines code inside of the 1,000 connections.

Machines now-a-days are generally powerful enough where you don’t really have to consider performance impact in most situations. But if you’re really concerned about the connections, then you should probably consider reducing the amount of connections that you’re creating - most games shouldn’t reach a point where there are 1,000 connections active at one time so perhaps there’s some repetition in the connections that could be turned into just 1 (or a few) connections.

So a connection that is not being fired is just memory usage. It’s small so you can get away with hundreds of thousands easily on most devices. If it never gets fired the amount of connections you can have is essentially unlimited in this sense up until you hit the memory limit of the device which will be a lot.

A connection that is fired is basically just a function call with a little extra indirection. So we can consider it a slightly heavier function call. So the real limiting factor is what you are doing in these functions. I can make like a million function calls per second on my computer before the call itself slows me down below acceptable frame targets (high end device, so assume lower for an actual game), but if the function is doing things then I will obviously not be able to run as many of them. The only real way to know how many you can get away with is measuring them.

One minor potential optimization to get away with more of them would be to write your own resolver so that the connections basically just say this needs to run at some point, then have your system distribute the calls over time instead of firing immediately which will allow you some extra headroom, but this will obviously delay some functionality (though the delay and order depends on how you script this)

But just having 1000 events won’t affect you at all. Firing them all at the same time may or may not affect performance depending on what the function actually does.

From your concern: “If I end up with around 1,000 connections at once, would that have a noticeable performance impact?”
Then answer: Yes, depending on what your Code is doing inside RBXConnection, you see that when you have a lot of RBXConnection,its DOES go to have some delay, lag. The Best way to example this is like “1,000 employees compete for work”
This also applies to not just 1000 RBXConnection, if you have just 4-5 RBXConnection, IF it is doing high computation, is it going delay
i have video that might be clear to your Concern : https://www.youtube.com/watch?v=BbIPalpAfaI