-
-
Notifications
You must be signed in to change notification settings - Fork 21.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
Optimize CowData
and LocalVector
functions .insert
and .remove_at
by using move semantics.
#100477
Optimize CowData
and LocalVector
functions .insert
and .remove_at
by using move semantics.
#100477
Conversation
bac918b
to
58e0957
Compare
…_at` by using move semantics.
58e0957
to
a636c04
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 am happy with this. This will safely use move constructor and assignment overloads where available, and fall back to the normal T& and const T assignment overloads otherwise.
As we add more move constructors and assignment operators to core types this will eventually be as fast as the original version, but without causing any uncertainty about safety in the meantime.
This is at worst a no-op, but since we already have move constructors on some of our more expensive types it won't be!
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.
LGTM
I did some benchmarks using https://github.com/godotengine/godot-benchmarks between master and this pr + #100483 and after running both master and that combination several times I can confirm that emitting signals is roughly ~10% faster with these changes compared to master, I also think that I see an improvement in the ObjectDB benchmarks but with 64 threads on my computer there's a ton of noise in the threads and it is hard to be sure. Function Callable seems to be 1% slower though, even after repeated runs. I can't explain it. |
Thanks! |
This PR uses move semantics to move regions in CowData, avoiding repeated copy assignments and destructions.
Safer, but still very fast, version of #100468. #100468 may still be re-opened if needed at some point, but it turns out most of the performance loss from these functions can already be avoided with this simple change.
Beneficiaries of this change include
Array
,PackedStringArray
, and other internal Vector types that use non-trivial elements.Additionally, some minor inefficiencies are addressed in
Vector
andLocalVector
implementations.Benchmark
I benchmarked the following code:
This yields:
121ms
and110ms
on Add move assignment and move constructor to Variant. #100426 (34fa0bf)22ms
and13ms
on a combined merge of this PR and Add move assignment and move constructor to Variant. #100426As such, it can be concluded that
remove_at
can be 5.5x as fast as before, andinsert
can be 8x as fast.Addendum
Arguably, push_back and pop_back() should be added to
CowData
, because quite a few callers have various ways of implementing these operations themselves. They could be accelerated with move semantics quite easily, and an efficient implementation would be considerably faster thaninsert
andremove_at
.