-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 FMT_REDUCE_INT_INSTANTIATIONS flag #1781
Conversation
fc7dfd9
to
c5026e2
Compare
@vitaut is there a make target to run a performance test? |
c5026e2
to
ed0bff9
Compare
This is a non-starter. A better option would be to keep |
Hmmm, I like it. I can make that change. |
Reduce code bloat by removing multiple instantiation of int_writer based on the <typename UInt> parameter. Rationale: - The only functions that gains a speedup by int size would be int_writer::on_dec()'s call to count_digits which uses CLZ. Thus to still take advantage of this speedup, we store the size of the int so we can use a switch statement to call the correct count_digits. - All other implementations of count_digits require some sort of looping that terminates when the value hits zero regardless of what sized int it is. Caveats: - There is a performance hit when dealing with and passing around 64-bit/128-bit values compared to 32-bit values on 32-bit platforms, and with 64-bit values on 64-bit systems. But this should not reduce the performance that dramatically. - There is also a performance hit for on_dec() due to the addition of a switch case. But, due to it size, this should reduce to a jump table. Resolves fmtlib#1778
ed0bff9
to
b8f53a0
Compare
When defined and set to zero, will use the largest available integer container for writing ints. The has the benefit of reducing instances the of int_writer class which will reduce the binary cost.
Looks good but I suggest renaming |
Add comment above FMT_REDUCE_INT_INSTANTIATIONS definition describing why a developer would use it.
Thanks! |
@kammce, BTW for future reference, what platform are you targeting and what are the savings with |
TL;DR: Saved 2024 bytes I'm surprised I didn't mention that at the start. Target CPU: Cortex M3 (although I test on M4F, M7 etc) Following flags were used to get the binary as small as possible during testing: #define FMT_STATIC_THOUSANDS_SEPARATOR ','
#define FMT_USE_FLOAT 0
#define FMT_USE_DOUBLE 0
#define FMT_USE_LONG_DOUBLE 0
#define FMT_REDUCE_INT_INSTANTIATIONS 1 Binary increased by 10,812 bytes when using fmt with the above flags turned on. Thus the binary amount saved is 2024 bytes. |
Reduce code bloat by removing multiple instantiation of int_writer based
on the parameter.
Rationale:
int_writer::on_dec()'s call to count_digits which uses CLZ. Thus to
still take advantage of this speedup, we store the size of the int
so we can use a switch statement to call the correct count_digits.
that terminates when the value hits zero regardless of what sized int
it is.
Caveats:
64-bit/128-bit values compared to 32-bit values on 32-bit platforms,
and with 64-bit values on 64-bit systems. But this should not reduce the
performance that dramatically.
switch case. But, due to it size, this should reduce to a jump table.
Resolves #1778
I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.