Skip to content
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

Way to opt out of string conversion? #121

Open
jaskij opened this issue Jan 23, 2024 · 2 comments
Open

Way to opt out of string conversion? #121

jaskij opened this issue Jan 23, 2024 · 2 comments

Comments

@jaskij
Copy link

jaskij commented Jan 23, 2024

I added Better Enums to my embedded project (a fantastic library by the way), and after converting two enums (one with 8 values, the other with 38), it added about 4 kiB of code size and 2 kiB of RAM usage. That may seem trivial, but in a device which has 64 kiB of flash and 8 kiB of RAM, it's a lot.

Experimenting a little, I found out that using BETTER_ENUMS_CONSTEXPR_TO_STRING has brought code size back down to what it was before using Better Enums. Which is fine, as is.

The thing is, my project does not use string conversion at all, and I would like to opt out of it if possible.

P.S.

I'm using ARM's build of GCC 13.2, with -Os -ffunction-sections -fdata-section and passing -gc-sections to the linker. Project is also compiled with LTO.

@aantron
Copy link
Owner

aantron commented Feb 2, 2024

It should be possible to add a macro to opt out of generating string conversions at all. I would strongly considering merging a PR. However, I understand from your message that you have a workaround for the main problem, so it might not be worth it. I understand that the remainder of this issue is about disabling string conversions for maybe safety or tidiness reasons. Is that right?

@jaskij
Copy link
Author

jaskij commented Feb 2, 2024

Mostly it's about code size. Depending on my own build configuration, I'm currently using over 90% of the allowed space. Better Enums without BETTER_ENUMS_CONSTEXPR_TO_STRING would push me over 100%, causing the builds to fail. In this particular project, I have a hardware limit that my whole release binary must fit in 52k.

Yes, there is a workaround. Disabling those string conversions entirely is honestly just build times and simple cleanliness at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants