Skip to content

More efficient translation #2968

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

Merged
merged 2 commits into from
May 29, 2020
Merged

Conversation

jepler
Copy link

@jepler jepler commented May 28, 2020

Length was stored as a 16-bit number always. Most translations have a max length far less. For example, US English translation lengths always fit in just 8 bits. probably all languages fit in 9 bits.
(in fact, all language string lengths presently fit in 8 bits)

This also has the side effect of reducing the alignment of compressed_string_t from 2 bytes to 1. So on average I estimate 1.5 bytes were saved per string.

Because the length of the string now counts against the compressed length, English now reports that one string increased in length. This message could be quieted, if desired.

testing performed: ran in german and english on pyruler, printed messages looked right.

Firmware size, en_US
Before: 3044 bytes free in flash
After: 3408 bytes free in flash

Firmware size, de_DE (with #2967 merged to restore translations)
Before: 1236 bytes free in flash
After: 1600 bytes free in flash

Length was stored as a 16-bit number always.  Most translations have
a max length far less.  For example, US English translation lengths
always fit in just 8 bits.  probably all languages fit in 9 bits.

This also has the side effect of reducing the alignment of
compressed_string_t from 2 bytes to 1.

testing performed: ran in german and english on pyruler, printed messages
looked right.

Firmware size, en_US
Before: 3044 bytes free in flash
After: 3408 bytes free in flash

Firmware size, de_DE (with adafruit#2967 merged to restore translations)
Before: 1236 bytes free in flash
After: 1600 bytes free in flash
@jepler jepler requested a review from tannewt May 28, 2020 14:02
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Very clever.

I think some explanatory comments in the C and Python code would probably be helpful to explain the underlying format.

@jepler
Copy link
Author

jepler commented May 28, 2020

I added some comments about how the string is stored that way, and why.

@jepler jepler requested a review from dhalbert May 28, 2020 17:57
@tannewt tannewt removed their request for review May 28, 2020 18:54
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thanks for the great documentation!

@dhalbert dhalbert merged commit 6ace4ee into adafruit:master May 29, 2020
@jepler jepler deleted the more-efficient-translation branch November 3, 2021 21:10
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

Successfully merging this pull request may close these issues.

2 participants