-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Simplify varray
#108118
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
base: master
Are you sure you want to change the base?
Simplify varray
#108118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me to simplify these functions; they're definitely more complex than they need to be.
However, initializer_list
has a hidden cost for non-trivial types. You can read about this problem here: godotengine/godot-proposals#12247
We've chosen to ignore this problem in most cases, since it's unlikely to lead to problems for most allocations.
However, as commonly called functions, varray
and vformat
deserve some extra care.
In practice, instead of using initializer_list
, I'd probably create the vector, reserve
on it (#105928 is scheduled to be merged early in 4.6), and then push_back
items from p_args
sequentially. This should both simplify and optimize the code. (or, alternatively, resize
and loop through the args, assigning to ptrw()
. This should be even faster but might be more annoying to implement).
fd38b09
to
aece13e
Compare
I changed |
I forget there is already #103917 😅. That should supersede |
aece13e
to
6dd71ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized args
necessitates a copy anyway, in the same vein that initializer_list
does. Therefore, this shouldn't be a performance regression.
The whole initializer_list
thing is still relevant, but since it has no satisfying solution yet, I'm OK just simplifying the code for now.
Reduce complexity of these two functions with initializer list constructor.
varray
should be ok because it is used together withsarray
, so not performace critical.For
vformat
I run both microbenchmark and a test project:code
result
master:
vformat
This PR:
vformat
code
result
master:
175.029 ms
172.557 ms
170.201 ms
172.307 ms
172.757 ms
172.753 ms
172.192 ms
171.617 ms
171.543 ms
173.941 ms
average: 172.4897 ms
This PR:
171.95 ms
170.445 ms
170.952 ms
168.081 ms
169.044 ms
170.402 ms
170.3 ms
171.469 ms
171.817 ms
169.767 ms
average: 170.4227 ms
both tests show no regressions.