How does "ref" only have benefit for large data structures?

Most of example with “ref”, I have seen ref used in array type such as the below

function automatic void DataRead(
input int num_data,
input string InputName,
ref logic [7:0] din_i[128];
ref logic [7:0] din_o[128];
...
);

I came across one benefit of “ref” during googling that the only benefit of a ref argument might be performance in passing large data structures like an array instead of using an input, output, or inout.

So I can’t find how “ref” have the benefit for large data structure.
Could you please help me to understand the usage of “ref” about the benefit for large data structure?

In reply to UVM_LOVE:

“ref” means that you’re passing the data by reference. In C terms, you could consider this like passing a pointer to the variable instead of the value of the variable itself. When you need to pass a large data set into a function, using “ref” means that you’re not making copies of that data but letting the function operate on the original values instead. This can cause issues if you forget what “ref” is doing, of course, since this allows the function to modify the original values.

In reply to jcraft:

Thank you jcraft, I’m trying to have a test for understand, How do I check the performance difference between a making copies or not making copies? Could you guide me please?

In reply to UVM_LOVE:

You should read this post:

They key benefit of a ref argument is when used with a time consuming task. Changes to the value of the argument get propagated through while the task is active.

The performance benefit of passing a large argument by reference is not straightforward. A lot depends on the usage and any optimizations a tool might have. For example if you have a very large array argument, but your function only access a few elements, pass by reference saves you the time to copy the entire array. But if your function accesses every element of the array, an indirect reference to an array element might be more time consuming than a direct reference to an array element.

You should use your tool’s performance profiler to make sure you are spending effort to reduce simulation time where it really matters.