-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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 String.repeat()
to optimize several String methods
#72288
Conversation
e56f640
to
bf05354
Compare
String.repeat()
to optimize lpad()
, rpad()
, pad_zeros()
, and pad_decimals()
String.repeat()
to optimize several String methods
bf05354
to
f58907a
Compare
f58907a
to
02680f5
Compare
02680f5
to
0e6f6e3
Compare
Instances I found but I'm not sure if I should edit: doc_tools.cpp, bvh_debug.inc, gltf_document.cpp I'll push these too, but I don't understand what some of the files are for, so I'll appreciate a review to make sure I'm not going over the top |
0e6f6e3
to
0b1cc19
Compare
5865644
to
a8c523e
Compare
Makes me wonder if we should add a |
af36023
to
3f94fd3
Compare
Generally it looks pretty easy to add and self-explanatory, so I wouldn't worry too much about over adding it (whether it will make any difference is another matter 😁 ). Seeing what appears when profiling is usually the gold standard for optimization, but on the other hand text output tends to occur in just a few frames, rather than continually, which can make it harder to identify via profiling. |
3f94fd3
to
0015a2c
Compare
Not 100% safe and not a bugfix. Makes sense to bump the milestone. |
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 besides the one potential change of the behavior.
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.
Looks good to me, once @kleonc comments are addressed.
0015a2c
to
6b84e25
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.
LGTM. Also makes the code nicer to read IMO :)
Great work! Thanks! |
kleonc and I optimized
String.repeat()
in #64489, so I wondered if there there is any engine code that is using iterative addition instead of this method. Nice surprise though, I found that even some user-exposed String methods could be optimized this way, namelypad_zeros()
,pad_decimals()
,rpad()
, andlpad()
. The latter two are even used inString::sprintf()
- I have no idea what sprintf does, but it looks important!The optimization should always result in performance gain, though I haven't benchmarked it extensively.Edit: It wasn't always a performance gain. It's just that the old
repeat()
was really slow, but the new one is still slower than a manual loop if it has 1 or 2 iterations. For a single iteration, the performance reduction was 15%, which I wasn't happy with, so I alteredString::repeat()
a bit to return the string directly ifp_count
is 1. This doesn't affect performance for other cases in any noticeable way.Testing new vs. old
rpad()
after that:RegEx used:
for \(.*\) {\n((\t)*).* \+= .*;\n((\t)*)}
and lots of manual sifting. A few I found with slightly different regexes too.