-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Add String::concat
and string.extend
functions to core for efficient String concatenation.
#99929
base: master
Are you sure you want to change the base?
Add String::concat
and string.extend
functions to core for efficient String concatenation.
#99929
Conversation
c3b639b
to
d6740c3
Compare
Should this method be exposed to scripting? Also, I wonder if the method name should be shorter if it's going to be used often. |
Hrm, well the function itself isn't compatible with GDScript since it's a template function; quite optimal for C++ but parameters must be known at compile time. I think such a function would be better suited for a separate PR. |
d6740c3
to
9c57fe9
Compare
concatenate_strings
function.concatenate_strings
function to core for efficient String concatenation.
b7f85fe
to
0c9ef0f
Compare
I rebased the PR on top of master, and simplified some of the changes. I think it's ready for review now. Not 100% happy with the implementation and name necessarily though, so I'm open to input for that. |
0c9ef0f
to
c222d0d
Compare
concatenate_strings
function to core for efficient String concatenation.String::concat
function to core for efficient String concatenation.
String::concat
function to core for efficient String concatenation.String::concat
and string.extend
functions to core for efficient String concatenation.
c222d0d
to
648e382
Compare
I have added |
648e382
to
3b43532
Compare
…enations where the contributors to the final string are well-known at the time of call.
3b43532
to
4009044
Compare
Small optimization and readability improvement.
String::concat
andstring.extend
enter the arena to join strings, and are the fastest method amongoperator+
,StringBuilder
andStringBuffer
for known-count string concatenations. They use compile-time logic to avoid needing RAM allocations for bookkeeping (likeStringBuilder
or multiplereallocs
(likeStringBuffer
) and is thus always faster than either.I have also changed all
Variant
conversions toString
to use theString::concat
function. This is not because of an urgent need to optimize these functions, but they serve as exemplary cases about how to use the function, and how this improves performance (1.6x in the case ofProjection
). Future PRs should address the various uses of repeatedA + B + C + D + E...
throughout the codebase where appropriate for optimization.I am open to renaming or moving the function.
Imo #100293 should be merged before this one, to avoid unnecessary additional renames.
Explanation
Take the example case
Vector4
. This has previously compiled like:This will now compile like:
Benchmark
I ran the following benchmark:
This prints:
4141ms
on master (a40fc23)2540ms
on this PR (b7f85fec53d9fc539f270fdde06563fe920bacef)Which showcases an improvement of
1.6x
in this particular case.