Skip to content
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

Improved memory efficiency for some text updates to bitmap_label.Label #167

Merged
merged 4 commits into from
Mar 13, 2022

Conversation

kevinjwalters
Copy link

  1. bitmap_label.Label - the self._bitmap and self._tilegrid is no longer recreated all the time
  2. This makes it more efficient for updates for text have the same length particularly in terms of avoiding creating a new Bitmap (and TileGrid) using more memory briefly and potentially causing memory fragmentation.
  3. Adding a new self._prev_label_direction to support label_direction properly.
  4. Fixed an unrelated bug in label_direction for RTL which would toggle direction if the value was repeatedly set - text reversal is now performed as text is set and not stored.
  5. _replace_tabs() function also enhanced to only do split/join if tabs are present - this is probably a rare case and it's inefficient to be making new text strings all the time.

The most efficient updates are now if the text string is the same character length as the previous value. The bitmap is cleared with fill(0) and re-written and this can cause flicker. The cognoscenti will be controlling display refresh, of course.

Kevin J Walters added 3 commits March 12, 2022 21:18
The tilegrid is also reused if bitmap has not changed.
New self._prev_label_direction to allow for tilegrid properties to be set efficiently.
Reusing existing bitmap needs clearing due to required use of skip_index on blit().
adafruit#166
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for the improvements @kevinjwalters!

Tested successfully with PyPortal and some variations of the examples scripts.

@FoamyGuy FoamyGuy merged commit 35b6410 into adafruit:main Mar 13, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 14, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_SI7021 to 4.1.0 from 3.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_SI7021#30 from tekktrik/doc/add-typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.22.2 from 2.22.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#167 from kevinjwalters/kjw-efficient-text-updates
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