feat: compress MicroCode's images with //% packable - #155
Merged
Merged
Conversation
thomasjball
approved these changes
Sep 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves MicroCode's images onto ui-core's new
//% packableimage compression (see related PR in microbit-apps/ui-core). 115 images now ship as one compressed pack instead of individualbmpliterals: pixel data goes from 18,328 B to 9,922 B, and the V2 image from 475,236 B to 457,468 B (-17,768 B) againstmain.Images are still authored as literals in
assets.ts.img.keys.jsonmaps MicroCode's keys (tile ids and string ids) to them,npm run img:gengeneratesimg.g.ts, andicons.getlooks them up with_img.get(key).What changed
assets.tsas//% packable+//% whenUsedliterals, restored from the earlier move toscripts/icon-literals.json."ui.thermometer"), so they no longer ship as separate literals.ui.MISSINGstays a literal, as the fallback.icons.getresolves the six operator glyphs andMISSINGitself, then everything else through_img.get.icons.get("disk"), andnumberToImage'snum2imagearray is replaced by_img.get("blocks" + n), so the classic-mode number images are decoded only if classic mode shows them.melodyEditorliteral collided withicondb.melodyEditor, which is drawn from a melody at startup. The packed one is nowmelodyEditorIcon, and tid 179 points at it.//% whenUsed. This annotation keeps them off the device.btn_stop,settingsGear,loud,quiet,arith_plus,arith_equals,onetofive) are now//% whenUsed, and drop out.Heap
A packed image is decoded into the heap on first use and cached for the rest of the run. In MicroCode: if every image is decoded, that's 18,328 B. Measured on a microbit with every packed image decoded at boot, the GC heap still had 13,380 B free and the app ran normally. The classic-mode number images cost heap only if classic mode is used.
Testing
main's icon table (98/98), checked against its uncompressed data.HOME_ADD_SETTINGSis false), so the number images were checked with a diagnostic build that forced it on: all five matched checksums computed from their source literals.microcode-v2.en.hexmatches a fresh build byte for byte.Other changes
README.md: the hex download link pointed atassets/microcode-v2.hex, a hand-committed build from November 2025. It now points atassets/microcode.hex, which the release workflow builds and commits..github/copilot-instructions.md: same filename correction.assets/microcode-v2.hex.package.json: addsimg:gen, and removesbuild:hardware:v2, which passed a--variantflag the current makecode CLI doesn't accept.ui-controls#v0.0.7->#v0.0.10(pxt) and@microbit-apps/ui-core#v0.0.6->#v0.0.9(npm).assets/hex/.Merge order
Merge after ui-core
v0.0.9and ui-controlsv0.0.10are tagged; until then CI can't resolve the new refs. Thennpm installto refreshpackage-lock.jsonand theimg-genbin link.