Skip to content

Batching - Show a label's first text 3x faster - #240

Merged
makermelissa merged 1 commit into
adafruit:mainfrom
mikeysklar:label-batch-glyphs
Sep 30, 2026
Merged

makermelissa merged 1 commit into
adafruit:mainfrom
mikeysklar:label-batch-glyphs

Conversation

@mikeysklar

Copy link
Copy Markdown
Contributor

What

Batching - A label asks the font for all of its letters at once, not one at a time.

Video

Why

Each new letter cost a font read and a garbage collection. #85 fixed this; #102 and #110 accidentally dropped it.

Measured

main this PR
Pi 5, LeagueSpartan-Bold-16.bdf 207.1 ms 97.3 ms 2.1x
Pi 5, Junction-regular-24.pcf 207.5 ms 22.1 ms 9.4x
Pi Zero 2 W, LeagueSpartan-Bold-16.bdf 1398.8 ms 677.5 ms 2.1x
Pi Zero 2 W, Junction-regular-24.pcf 1412.4 ms 206.4 ms 6.8x
Pi 5, HX8357, 20 labels, refresh after each 4.24 s 1.45 s 2.9x
Pi Zero 2 W, ILI9341, 16 labels, same 20.00 s 7.08 s 2.8x

Font rows: one label.Label, 44 characters, newly loaded font, median of 10 runs.

Tested

Raspberry Pi 5 and Pi Zero 2 W with Blinka, Python 3.13.5. Not tested on a CircuitPython board.

check result
pixels drawn, 4 fonts, label and bitmap_label same as main
label whose letters are already loaded same time as main
two line label update, adafruit_bitmap_font 2.4.2 and 2.4.3 same time as main
terminalio.FONT, which has no load_glyphs works

Scope

Repeated letters and newlines are not sent to the font. TextBox is unchanged.

AI assistance

Written with Claude Code.

A label asked the font for one glyph at a time, so each new character read the
font on its own and ran gc.collect(). Load the text's glyphs in one pass first,
as adafruit#85 did before it was dropped along with the "M" glyph load in adafruit#102 and adafruit#110.

The font is given each character once and never "\n". PCF and LVGL fonts load a
repeated character again when handed a string, and a BDF font reads the whole
file looking for a newline glyph, on every update before adafruit_bitmap_font
2.4.3.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@makermelissa makermelissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, looks good.

@makermelissa
makermelissa merged commit b368c38 into adafruit:main Sep 30, 2026
1 check passed
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 2, 2026
Updating https://github.com/adafruit/Adafruit_CircuitPython_TLV320 to 1.4.0 from 1.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLV320#16 from FoamyGuy/support_32000_sample_rate

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 5.0.6 from 5.0.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#240 from mikeysklar/label-batch-glyphs

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_Moonshine_Klatt, Adafruit_CircuitPython_PicoTTS
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