Skip to content

translate: drop the uncompressed length from each message - #12010

Merged
dhalbert merged 3 commits into
adafruit:mainfrom
MakerClassCZ:translation-no-length
Dec 1, 2026
Merged

dhalbert merged 3 commits into
adafruit:mainfrom
MakerClassCZ:translation-no-length

Conversation

@lynt-smitka

Copy link
Copy Markdown

Follow-up to #12007. Each compressed message started with its uncompressed length (8 bits, 9 for ru). This drops it. The generator pads the last byte with the start of a code longer than the padding, so the decoder stops at the symbol that runs past the end of the data. The length is found by decoding without storing. If a Huffman table has no code long enough to pad with, the generator adds a qstr escape to it.

Board Language Change
feather_m0_express pt_BR −236 B
feather_m0_express de_DE −236 B
feather_m0_express ja −292 B
feather_m0_express ru −308 B
pybadge de_DE −460 B

All 20 languages build for feather_m0_express. On a PyBadge in de_DE, ja, ko and ru, exception messages, locale and tracebacks match the base build, and the unix coverage tests pass.

Each message is now decoded twice per raise, so raising an exception with a C message is about 30% slower (de_DE: 168 → 222 µs on a PyBadge).

Personally, I find it a bit tricky, but the savings are not bad.

Created with LLM 🤖.

Each compressed message started with its uncompressed length (8 bits,
9 for ru). Drop it: the generator pads the last byte with the start of a
code longer than the padding, so the decoder stops at the symbol that
runs past the end of the data. The length is found by decoding without
storing. If a Huffman table has no code long enough to pad with, the
generator adds a qstr escape to it.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

requests are only for more comments

Comment thread supervisor/shared/translate/translate.c Outdated
s->last = c;
}

// UTF-8 encode a code point from the BMP.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the BMP?

Comment thread supervisor/shared/translate/translate.c Resolved
Comment thread py/maketranslationdata.py Outdated
Comment on lines +665 to +666
# compress() pads a message's last byte with the start of a code longer than 7 bits.
# If a table has none, split its longest code to add a qstr escape.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This deserves a little more explanation.

Comment thread py/maketranslationdata.py Resolved
Comment thread py/maketranslationdata.py Resolved

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the explanations!

@dhalbert
dhalbert merged commit 4830fa9 into adafruit:main Dec 1, 2026
720 checks passed
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