which are faster in GDNative: godot Array/Dictionary or C++ sandard library containers

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lurker

When I use GDNative plugin writen in C++, can I gain more performance by using standard library containers (adequate to use case) instead Godot’s Array, Dictionary?

:bust_in_silhouette: Reply From: r.bailey

A little late, but better last than never.

From my experience working with the the Godot engine you can get massive performance gains by using the standard library containers/classes in Gdnative. You could get more if you write your own, As the standard library containers are generics and not specific to what you are trying to do. Rewriting your own container class is of course not recommended , just an option.

This is apparent when you do anything that is sizeable, because they don’t have to run within the constraints of the engine. Generally most classes that are that are within the the engine are good enough for general usage. Yet can have crashing issues or performance issues depending on what you are doing. By sizeable for example I mean do string manipulation on strings bigger than 100000 characters, same thing with most built in classes, Arrays, Dictionary, etc.

Gdnative is a bit of a learning curve though, and will require you to learn a decent amount of the engine to get things done, but if performance is an issue then you should be using Gdnative to do the heavy algorithms within to compute values and pass them back to the engine.

I will link a Youtube video below that helped me get started, I didn’t make this, but it definitely lead me in the right direction. GL

10,000 subs GDNative YT

Thanks for answer. I have tried migration of code to std containers and got performance boost.

Lurker | 2022-03-10 07:04