Skip to content

Glyph compression#254

Closed
daveallie wants to merge 3 commits intomasterfrom
feature/glyph-compression
Closed

Glyph compression#254
daveallie wants to merge 3 commits intomasterfrom
feature/glyph-compression

Conversation

@daveallie
Copy link
Member

@daveallie daveallie commented Jan 5, 2026

Summary

  • Glyph compression using zlib conditionally if the compressed data is at least smaller than 90% of the original
    • It is possible for small glyphs to get bigger when using DEFLATE, and this seems to work best on the larger fonts
  • Inflate the compressed glyphs at render time

Additional details

  • Reduces flash size from 5,624,290 (85.8%) to 4,730,684 (72.2%), a 15.8% reduction
  • For bookerly 14pt, this seems to incur a cost of about 300ms per full page render of text
    • Went from about 700ms to do both BW and gray pass to ~1000ms
    • I believe I can lower this further by using a small LRU cache in the font to hold often used glyph data (perhaps we also only ever use the cache for compressed glyphs too)

@daveallie daveallie force-pushed the feature/glyph-compression branch from 461d682 to 551e572 Compare January 5, 2026 12:13
@daveallie daveallie mentioned this pull request Jan 5, 2026
@jonasdiemer
Copy link
Contributor

30% slowdown (in everyday page rendering) for 15% space reduction doesn't sound like a good trade off. We should rather move fonts to SPIFFS.

Instead of caching, maybe consider only compressing rare glyphs?

@DJPoulter
Copy link
Contributor

Is there any way to have font files on the SD card and then put into flash when they are selected in the settings? This would allow us to have more fonts/sizes.

@khromov
Copy link
Contributor

khromov commented Jan 9, 2026

Agree with Jonas, page change responsivity is the main "feature" of an e-reader, it trumps more fonts for sure. If you feel this is a "must-have", perhaps it's possible to consider creating a "light" version of Crosspoint with limited font choices for people who prioritize responsiveness?

@jonasdiemer
Copy link
Contributor

Is there any way to have font files on the SD card and then put into flash when they are selected in the settings? This would allow us to have more fonts/sizes.

We will do that after 1.0 when we are ready to ditch the stock os (and hence can overwrite the SPIFFS partition of the embedded flag with font cache data loaded from SD card)

@daveallie
Copy link
Member Author

Yeah agree that the current tradeoff is not yet worth merging this, unless that time cost gets quite low this isn't a valid path. I mostly put it together to experiment with the idea.

"rare glyphs" is a bit of an interesting one as it's likely language dependent, for example for my books all Cyrillic glyphs are "rare", and for others, other sets will be less common.

SPIFFS is a much more reasonable alternatively (or even just expanding the main app partitions further), before doing so I'd like to explore what the impact is to the stock firmware if the SPIFFS partition is missing their expected data.

The TLDR is that this PR won't get merged in as it stands.

@KraXen72
Copy link

what about zstd (z-standard) compression? from a quick search, it seems to outpreform deflate in decompression speed.

@daveallie
Copy link
Member Author

I believe the zstd dictionary is significantly larger (resulting in needing 128MB of RAM to even just set it up). There might be some dictionaryless one-shot decompression like we're doing with deflate, but I haven't looked into it.

Also, given the small volume of bytes we're decompressing at a time (but doing it many many times), the throughput speed of the compression algorithm isn't the bottle here (afaict) but instead all the setup/teardown, which would likely be similar for zstd.

@carpentiers
Copy link
Contributor

How about Tamp?

@daveallie
Copy link
Member Author

Planning to reapproach this with something like Group5 using bb_paper, will have a chat to bitbank2 about it.

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.

6 participants