Global variable with multiple nested objects

I've a query, while writing and reading the data to the global variable having multiple nested objects from different flows and nodes ...will it leads to any performance issue in node red ?
my global variable will be like this -->

{"vsecc":{"connector1":{"em":{"freq":{"real":{"value":{"type":{"int":{"value":{"data":{"data":{"data":{"data":{"data":{"data":{"data4":20,"data5":20,"data6":20,"data7":20,"data3":20,"data2":20,"data8":20,"data1":20,"data9":20,"data10":20,"data11":20}}}}}}}}}}}}}}}}

For our project I'm using the centralized data in one global variable under many layers of data splitted into sub objects, is this better approach to store data under single variable ?

There will be a "cost" once objects become very large (objects with 100k+ arrays). The example you gave is very small, there will be no measurable performance impact. However, you could run into potential problems when multiple flows write into the same object and it is written to disk while other flows are reading+writing into the same object.

Maybe I misunderstand but doesn't that mean that your value "data7", already rather cryptically named, will be stored at globalvariable.vsecc.connector1.em.freq.real.value.type.int.value.data.data.data.data.data.data.data7?

Do you need to use a global variable to store this value anyway?

I just have given an example data structure, how I'm storing the different variables under single.
I just need info about like will it effect the performance of node red (CPU usage) while accesing the global variable having length nested objectsand sub objects simultaeously from different nodes

How are you getting, modifying and setting the data? A short example of the code you are using please.

Are you using persistent context (so the data persists over a node-red restart)?

No, I'm not using the persistent storage..I'm just using the runtime storage

And the other question?

No it won't.

Thanks, but someone had commented above like reading+ writing on to the same variable simultaneously ...creates issue

nodejs is single threaded so a simultaneous read write is not going to happen, as each node has to take its turn.

So, updating the same variable from different nodes at the same time using common trigger for all the function node where each function node will set the same global variable...so in this case also, it wont be a problem ??

your question is about writing to context, each node has to take its turn, so writing should not be an issue. You may find concurrency issues with the data not being what you expect, if two nodes have written to context, the first node that writes the data may find the data has been changed by the second node, and this may cause issues you may not of expected.

That's true but you made it clear that you only want to know if it will affect CPU usage so that's the question I answered.

If you trigger them all at once and they all update the same variable, then they will run one after another, so at the end the variable will be set to whichever function ran last, but you will not know which one ran last.

1 Like

:+1:Thanks for the information !