In Javascript: memory allocation compared to large object manipulations

I have a JavaScript module that supports and processes a lot of data. I have four large structures - each basically an object of an object of an array of objects. And they have a lot of data. When the user does something like delete or update, I need to go through each of these structures and reliably modify the structure to reflect the change. In some structures, depending on the user’s actions, I don’t know which “sheet” object I need to change, so I need to iterate over everything, etc.

An alternative to manipulating these large structures when a change occurs is to nullify them and restore them from the original data. And here is my question:

In terms of performance, in Javascript, would it be more optimal to go through and modify existing (large) data structures, or just rebuild structures from their original data?

I am sure that the answer may be "it depends", but a) suggest a large amount of data; b) assume frequent changes to these data.

+6
source share
2 answers

Sorry, I know that you are not expecting an answer, but “it depends” :-) However, I think the best answer I can give you is what I did when I came across the same problem : I implemented a simple testbench to measure the time taken to perform certain operations on a huge superobject: I had average time measures for different levels of information entropy, and it turned out that the quickest solution was to restore the structure from raw materials. I specifically noticed this in Internet Explorer. It is possible that IE does not work well in loops (I reflect), and moving a superobject was rather slow than restoring it. Thus, this may not only depend on the structure of the superobject, but also on the javascript mechanism.

But, again, this is my business. I recommend implementing a simple test bench: it does not take too much time, but makes you get good results at the end; -)

EDIT

As an add-on, I wonder if there will be a creation of a super-object on the server side, and then send it back to the browser, since the JSON object will improve the results or not. I do not know if this is possible in your case. You can implement some kind of AJAX-accessible PHP script that receives commands (such as insert, delete, rename, whatever ..), and then it sends a new JSON object to the browser, which only the object will parse (maybe a quick operation? )

+1
source

I'm not sure if this applies here, but it reminds me of a blog post from wingolog.org on a v8 implementation:

Ed: Vyacheslav Egorov writes that what V8 supports is actually a source of function, not AST. It reanalizes as necessary. Has the meaning. I remember how Lars Buck said in the video that the source is the most compact IR available, and perhaps it is.

Basically, when v8 compiles JavaScript, it only saves the source data (source code), because in this case the memory size affects performance to a greater extent.

0
source

Source: https://habr.com/ru/post/922354/


All Articles