-
-
Notifications
You must be signed in to change notification settings - Fork 20.9k
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
Use LocalVector
in Array
#97804
base: master
Are you sure you want to change the base?
Use LocalVector
in Array
#97804
Conversation
This makes calls to |
@AThousandShips This is copying. Immediately after copying, the user will want to make some changes to the array, which in any case will make a copy on write. |
That's not granted though, you can't assume that just because someone makes a copy they want to mutate it, it might be passing an argument |
When passing arguments, we use this constructor: Array::Array(const Array &p_from) {
_p = nullptr;
_ref(p_from);
} Where no copying occurs. |
That's not the only case though, for example constructing a For example: var my_base_array : Array[Node]
var my_derived_array : Array[Node2D]
...
my_base_array.assign(my_derived_array) Will not invoke any copying currently, but will with this Or any use of This is also used in godot/core/variant/variant_parser.cpp Lines 1351 to 1365 in f032af7
This will now always perform a full copy of the data instead of just referencing it |
There are two performance aspects here we need to benchmark and assess:
|
Aha. I'll look into that. For the first point, I think godot-benchmark will be enough. For the second, I will do something like passing the parameters of various types of arrays and iteration or something like that and measuring time. |
fd8f2b8
to
3d9a8b5
Compare
Benchmarks: About Lines 248 to 275 in f032af7
Where no COW occurs.
|
Due to the fact that
Array
behaves likeRefCount
(if we have two references to the object and change one array, the other also changes).Output:
Array has a built-in
SafeRefcount
for this. So, using COWVector provides overhead.