I’m working with gdscript, I used a lot of Node/Object as keys or values in dictionary, I wonder if this will cause performance problem. How are they stored exactly? Is it String or their instance_id or something else? Does store such type variant take a lot of time? Should I avoid it?
If it’s expensive, how do I find an alternative way to refer to it (in a manner similar to dictionary)?
I tried to find in the documentation, but I failed to. I asked a lot in a row but I don’t really mean to dig into it, any help is appretiated. Can anyone please help to explain?
They’re stored as a reference (pointer) to the object. These aren’t any heavier than a regular variable in terms of memory. Dictionary additionally does some hashing, but unless your object or dictionary is huge, this shouldn’t be a problem.
No
No
No need to, do what you’re doing. If you ever encounter a real memory or performance problem - then start looking into the alternatives.
Alternatively, you can store instance_id as a key or a value - this will for sure be easier for the engine to handle, but it comes at a cost of convenience as you need to additionally handle serializing and deserializing the id.
Use Profiler to find out if this is actually the bottleneck of your performance, never assume anything.
Thanks for the answer! I’m worrying this for I’m going to intensively add Nodes to dictionarys for every frame, now I understand better what I’m doing. And the last advice is gold