Talking across too many objects causes big lagg?

I’m playing with threading and coroutines for a voxel chunk generation machine. I at one point had a master script that was storing all of the world data in Dictionary&ltstring, CubeType[,]&gt like structures and then the chunks themselves would ask for this data when they needed it.

In short, running through a 20x20x20 chunk and asking the parent transforms script “gimme what kind of block is at 5,5,5” 8000 times was posting around a 1.3second lagg on my not so awesome computer.

I changed the master script to calculate then assign the chunk its own copy of data for use and sure enough its down to 0.033seconds again.

There are certainly other small factors here and there, but I noticed a huge drop in performance as soon as I setup the master handler script. Is this something to avoid in the future whenever possible? Some people are so livid about OOP and making lots of a little scripts to do everything. Not when lots of small calculations and data transfers are involved though?

i/we cant give definite answers before seeing and understanding exactly what you are trying to do with your project and what compromises can be made.

Obviously running separate scripts on a billion objects is a big NO.

there are several creative Technics developers have used to get around these sort of problems and accomplish big stuff.

For Example: scripts that only run a certain distance from the camera…yay

Remember, scripts in update loop though your masterscript i guess about 60 times a second.

an obvious answer would be to limit how many times per second your master script needs to do whatever it is doing.

super simple javascript code to limit your master code to calculate only every third frame or 20 times a second:

var slow:int;

    function Update (){
    slow = slow -1;
    if (slow<1){slow=3;
    
    //put all the real heavy script here to cut pcu usage to a third 
    
    }}

now you should preform 3 times faster.
and your users hopefully wont notice 60* per second vs 20.

tanaoshima is exactly right. you got to look at the big picture first and create a creative plan to arrange your game to accomplish whatever you are doing.

No one had a clear answer though Mike’s logic is certainly sound. The assumption is that the data does not already exist, it needs to be created. Does creating that via multiple scripts affect speed rather than using only one script to run all the methods.

I setup a test:

a 50 x 50 one-sided (top only) voxel array generates 51x51 vertices. It then generates the mesh and updates it.

Approach 1:
100 times the vertex calculations are run by calling a GetNoise function within the mesh generating script. The mesh is then generated and applied.

Approach 2:
100 times the vertex calculations are run by calling a GetNoise function on a second script attached to the same transform. The mesh is then generated and applied.

Conclusion: approach 2, calling the GetNoise function (written exactly the same) on a second script, adds 0.4s to the processing time on my cheap little laptop. So there is clearly a difference in moving off object/off script and back. Certainly not much, but in the original post I was running many tens of thousands of calls between scripts and it was very clearly slower.