-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arrays and vectors always resize after a push or a remove #22561
Comments
CC @karroffel |
The same should happen when you do it from GDScript or VisualScript or any other language. As you can see it's going through the |
Having it call resize sounds legit, isnt it supposed to resize the capacity instead at every power of two? |
Taking a look at this, and indeed, it seems like Regarding the growth factor, I'm personally leaning away from 2 (and instead, towards something like 1.5) based on info from the Dynamic array wiki page and this StackOverflow discussion. Specifically, a growth factor of 2 has the following disadvantages:
Thoughts / suggestions are welcome! |
Any movement here? I'm currently writing a grid based A* implementation following up on a bunch of people in the community using A* in that way anyways and it being possible to optimize it quite a bit with that in mind, but I'm finding that the final limit I'm hitting is the same as was found in #28925, namely that the constant reallocs occurring due to the arrays resizing when the open list is pushed to/removed from has a fairly big performance impact. So I also did a quick experiment with the new grid based A* (called As you can see just replacing the open list alone leads to > 2x improvement, so I'd love to see some movement in this issue! I imagine mitigating the issue here would lead to improvements across the entire Godot codebase (I also ran a similar test with the previously improved default A* and also saw a nearly 2x improvement just by replacing the open list with |
Is it actually similar to #24731 ? |
@Zylann Ah yes, you're quite right, it is indeed, I'd missed that one existed! The only thing here is the resize by power of two does not occur on removing elements so that always causes a realloc right now afaik. ... But it's the very same issue at the root anyways, the lack of a capacity in the container. |
Ensure COWData does not always reallocate on resize, fixes #22561
(cherry picked from commit 0c24a84)
Godot version:
3.0.6.stable.mono
OS/device including version:
Linux, Ubuntu 18.04, g++
Issue description:
I'm writing a library in C++ with GDNative and running it in Godot with C#.
The library is returning an Array of Vector2.
The problem is that every time I push an element, it always trigger a resize of the corresponding Vector.
Steps to reproduce:
If I write this code:
Valgrind shows that it's triggering resize every time instead of once every power of two.
The text was updated successfully, but these errors were encountered: