I read some threads about how the parameter passing of the javascript function goes when the parameter is an object; I noticed that there is a lot of confusion in the method of going through, at least in terminology: link-by-link, link-copy, etc. This question is not about what this transfer method is called or how it works internally, but somehow answers this question.
I have a large, very large object to jump to a function as an argument; I need to understand whether the transfer of an object to an object is implied by some copy of the object, so the memory consumption, computational efforts, risks of memory leak are proportional to the size of the transferred object, for each function call (I have many calls), or if it is transmitted with non-standard proportional consequences.
Since changing the properties of an object in a function changes the object in the external scope, but the object itself does not change, I think that the memory used inside the function to store and “reference” this parameter does not depend on its size, because the object seems is not copied, but I have to be sure of that.
Sorry for the poor explanation of my English!
EDIT: the answer is somehow an idea of the JS transfer mode, but the main problem is to increase the productivity of the practical case, so any theoretical information has good use, but the most important information that is needed is the consumption of computer technology and memory.
Use case 1 (performance): let them say that I have a function that accesses two members of its argument and writes some result to the third, executed 1000 times on 1000 different objects. The question is that a hypothetical cycle will take almost the same time if an object is made of only 3 related properties and does it have another 100 properties? Any difference can be caused only by service data with parameters or a choice of properties inside a larger object? The actual test can depend a lot on the browser, so I need a technical, general answer to this question.
Use case 2: I have a 100 MB object passed to a function. At runtime, do I have a 100 MB increase in memory usage? Thus, any memory leak introduced, for example, by uncontrolled shells, is more dangerous.
performance javascript function object
Nillus
source share