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 str_from_int
function
#7056
Add str_from_int
function
#7056
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.
This increases FPS in the editor by ~25% when many numbers are rendered for switch/tele/speedup/tune layers or with "Show Info" being enabled.
That's very nice numbers. :o Thanks for pursuing this.
I wonder whether this could be made drop-in, i.e. check if the format
parameter of str_format
is "%d"
and if so, call std::to_chars
?
This would be 1.7x slower with GCC (https://quick-bench.com/q/zYJQrmQFwC6HUPagPduDs5ooqQ0) and 36x slower with Clang (https://quick-bench.com/q/D-aRHQtGDCCSPRNTFujS3W_2rYU). We'd still need to use varargs, which is always slower than passing a single integer by value. |
How about a constexpr version of format? You might be able to match the performance that way |
Cool site! :o The Clang benchmarks look moot, it inlined the function completely, i.e. it's no longer converting strings to ints in the benchmark at runtime.
Even though this shouldn't™ be the case, it apparently is. I tried to look at it with godbolt and the compilers generated shitty code for variable args. |
This will make compile times slower though, I don't think that's desirable. |
14b04da
to
f59c8eb
Compare
f59c8eb
to
bc0472a
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.
Looks good to me, thanks!
d2916b6
to
1b38a03
Compare
Add more efficient function for formatting integer values as strings. A benchmark shows that using this function is significantly faster than using `str_format`. It is faster by a factor of 220 with Clang 15.0 O2 (https://quick-bench.com/q/BlNoLnlyqxipf4jvsFTUxKMHDJU) and by a factor of 11 with GCC 12.2 O2 (https://quick-bench.com/q/Fxf9lDCTqXBF4pIa_IyZ5R0IqYg). This increases FPS in the editor by ~25% when many numbers are rendered for switch/tele/speedup/tune layers or with "Show Info" being enabled. The additional static analysis for `std::to_chars` revealed that the wrong size was used in `CHud` for `aScoreTeam[TEAM_RED]` and `aScoreTeam[TEAM_BLUE]`. This requires incrementing the macOS deployment target from 10.13 to 10.15.
1b38a03
to
d2c9750
Compare
Add more efficient function for formatting integer values as strings.
A benchmark shows that using this function is significantly faster than using
str_format
. It is faster by a factor of 220 with Clang 15.0 O2 (https://quick-bench.com/q/BlNoLnlyqxipf4jvsFTUxKMHDJU) and by a factor of 11 with GCC 12.2 O2 (https://quick-bench.com/q/Fxf9lDCTqXBF4pIa_IyZ5R0IqYg).This increases FPS in the editor by ~25% when many numbers are rendered for switch/tele/speedup/tune layers or with "Show Info" being enabled.
The additional static analysis for
std::to_chars
revealed that the wrong size was used inCHud
foraScoreTeam[TEAM_RED]
andaScoreTeam[TEAM_BLUE]
.This requires incrementing the macOS deployment target from 10.13 to 10.15.
Checklist