I was curious how many bytes e.g. a Node
takes compared to a plain Object
, so I modified the engine’s code to print the sizeof
various types. This is on x86_64 Arch Linux, using gcc 15.1.1, but I think the results would be fairly representative of other platforms as well.
First, with target=editor
, which enables various functions only useful when running the game from the editor:
Object: 376
RefCounted: 384
Resource: 576
Node: 1032
Node2D: 1408
Node3D: 1320
Control: 2504
Then with target=template_debug
, which compiles with debug info but without editor-specific debugging tools:
Object: 328
RefCounted: 336
Resource: 504
Node: 976
Node2D: 1352
Node3D: 1240
Control: 2440
Finally, the one that really matters, target=template_release
:
Object: 320
RefCounted: 328
Resource: 496
Node: 968
Node2D: 1344
Node3D: 1232
Control: 2432
As you can see, Node takes about twice as much memory as Resource, and three times as much as RefCounted. RefCounted seems to be a better default choice than Object, since the difference is very small, also in terms of performance.
I added Node2D, Node3D and Control only for completeness, since you typically don’t have extremely many of these – and if you do, you’ll run into bottlenecks elsewhere before these few kB start to matter.
Hopefully this will help someone decide whether to avoid using nodes for everything