-
Notifications
You must be signed in to change notification settings - Fork 38
Reduce memory usage for text creation: bitmap_label #76
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
Comments
Is the core problem with the current implementation the overhead of the TileGrid class? How does this change as the text gets larger? The TG model saves glyph bitmap duplication at the expense of the TG fixed overhead and the cost of storing it in a group. Note, I wouldn't include the current background bitmap in the calculations because it's easy to optimize on it's own. |
Short answer to your question: Conclusion:
|
@kmatch98 Thank you for the empirical numbers! I think the textmap numbers are a bit misleading though because it's a fixed overhead of 320 x 240 // 8 = 9600 bytes which means label is a better choice for strings of 9600 // 125 = 76 characters or less. We can raise this number by reducing the overhead of each tilegrid. I think the cost of each character now is:
Only the first two bullets apply when a duplicate character is used. I think we should add a |
I reviewed my code and decided to eliminate any difference due to the import statements. So now the import statements are consistent for all tests. Here is chart with the updated overhead: @tannewt To check your comment about the third bullet, reran the code with a string with just repeated "M" in it. I see the same ~100 byte incremental memory usage when each character is added, even thought it is a duplicated glyph. Am I missing something? Please note that I load the glyphs before entering the loop:
As for overhead, the updated numbers show that Raw data and Test Code for
|
To keep from getting lost in the empirical measurements: Once we better define what the problem is, I want to make sure we have an agreed strategy before going any further. I see two approaches to consider:
Based on what I have seen the current Y'all's feedback is welcome, requested and appreciated! @FoamyGuy @tannewt |
Nope! I didn't realize you were preloading the glyphs.
I would do more 2 than 1. To me, a label is a small amount of text. Hundreds of characters is not a label but rather a paragraph or text area. I don't think it needs to be in a different library though. It should just be a different module (aka file) in this library.
I agree that 100 bytes per character is a lot. We should take a look at TileGrid to see if we can reduce that overhead. I don't think that is the primary concern of this investigation though because the memory errors people hit are due to large consecutive allocations because of the group containing many characters. 100 bytes per TG is a lot but at least they are separate memory chunks. I'd propose adding a TextArea class that takes rectangular bounds and allocates a bitmap for the bounds once up front. Then, text can be laid out into it repeatedly without additional allocations.
Thank you for your in depth thoughts on this! |
Thanks @tannewt. I remain suspicious of TileGrid, it seems like the overhead it excessive but I can't understand the code well enough to point to the issue. After good discussion with @FoamyGuy this morning I decided to start with the direct drop-in replacement Once that is done, I'll start on #2. I've already been down this road with TextMap, so those features will be my starting scope. Main scope is to decide what features to bring from recent updates to But before I turn to #2 , I'd like elicit feedback on the top features desired. I'm not sure the best forum to do that. I suspect the easiest method is to create something and then people will say "I wish..." The In-the-Weeds time is helpful, but I'm unsure if we can collect specific text-realted feedback there. I am totally new to this kind of large-scale collaborative development, so I'm open to your suggestions how to scope a new add-on file to the display_text library. |
I think the first place to look for overhead is here: https://github.com/adafruit/circuitpython/blob/main/shared-module/displayio/TileGrid.h#L37 Most of it could be simplified for the single tile case and we could therefore split much of it into a separate sub-allocation when more than one tile is used. |
Closed with: #79 |
In order to reduce the amount of memory for displaying text, @FoamyGuy and I are developing a new "label" class that will use a bitmap instead of a group of TileGrids to store the text. Here is a proposed strategy for this new "bitmap_label" Class:
bitmap_label
Class definitionInput parameters:
text
a required parameter (Note: This will flag if someone creates a bitmap_label with no text, which doesn’t make any sense.)max_glyphs
parameter, but ignore it.Do we want to keep self._memorySaver? (Note: If so, update this to a class variable)
None
if self._memorySaver == True.Since the bitmap_label has limited edit capability after creation, minimize the instance variables that are stored
Add getters/setters for:
Getters only (or does it regenerate from scratch if this is changed?)
_memory_saver
option)Add scale capability (this should be handled in the Group)
General steps for
_init_
of a bitmap_label instance:Note: Negative padding cannot be used. (This would require adding a third color to the palette, which would inflate the bitmap_label bitmap memory usage.)
bounding_box
values.The text was updated successfully, but these errors were encountered: