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

Reduce memory usage by changing const strings to string literals. #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hexfet
Copy link
Contributor

@hexfet hexfet commented Jan 16, 2019

For the t8sg_v2_plus build:

Names #defined as string literals
ROM: 0x08003000 - 0x0803b2c4 = 224.69kB
RAM: 0x20000000 - 0x20008df8 = 35.49kB

Names as char array (master at e33da01)
ROM: 0x08003000 - 0x0803b34c = 224.82kB
RAM: 0x20000000 - 0x20008e00 = 35.50kB

@hexfet
Copy link
Contributor Author

hexfet commented Jan 16, 2019

Started exploring this from curiosity of which approach is best. This SO page has some interesting discussion.

@PhracturedBlue
Copy link
Contributor

interesting. I still don't like this approach, but clearly there is some benefit to it. I'll be interested in whether we see the same reductions when combined with a newer compiler

@hexfet
Copy link
Contributor Author

hexfet commented Jan 16, 2019

Results with latest compiler below. Seems like the only advantage is size. Thought it would make the file look cleaner but it doesn't. Perhaps a typedef would be good for that. Don't mind to close this and just keep in mind if bytes get short again.

With
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.1 20181213 (release)
[gcc-8-branch revision 267074]

Names #defined as string literals (const_to_define)
ROM: 0x08003000 - 0x0803ae2c = 223.54kB
RAM: 0x20000000 - 0x20008e00 = 35.50kB

Names as char array (master at e33da01)
ROM: 0x08003000 - 0x0803aea4 = 223.66kB
RAM: 0x20000000 - 0x20008e00 = 35.50kB

@howard0su
Copy link
Contributor

Do u want to try with lto8.2 brach to see the result?

@hexfet
Copy link
Contributor Author

hexfet commented Jan 16, 2019

lto8.2 + const_to_define
ROM: 0x08003000 - 0x08039830 = 218.05kB
RAM: 0x20000000 - 0x20008d68 = 35.35kB

Please consider an environment variable to disable lto when running make. It adds significantly to the build time so it will be good to have an option to build without it during development.

@PhracturedBlue
Copy link
Contributor

not really a discussion for this thread, but that will be challenging for at least the 7e, since we'll likely take advantage of the extra space it provides...

@howard0su
Copy link
Contributor

sorry, 7e LTO build is not done yet. I didn't get it working....

Copy link
Contributor

@PhracturedBlue PhracturedBlue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is enough improvement in this method to implement it now. I'm open to understanding why the compiler isn't doing a good job with string arrays, but I am not ready to accept this at this time.

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

Successfully merging this pull request may close these issues.

4 participants