Skip to content

Cache fonts for lower memory usage #32

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

Merged
merged 4 commits into from
Dec 5, 2020

Conversation

makermelissa
Copy link
Collaborator

No description provided.

@makermelissa makermelissa requested a review from a team December 3, 2020 22:34
@makermelissa
Copy link
Collaborator Author

makermelissa commented Dec 3, 2020

Test script I used:

from adafruit_magtag.magtag import MagTag

magtag = MagTag()
magtag.add_text(
    text_font="Arial-Bold-12.bdf",
    text_position=(10, 10),
)
magtag.add_text(
    text_font="Arial-Bold-12.bdf",
    text_position=(10, 30),
)
magtag.add_text(
    text_font="Arial-Bold-12.bdf",
    text_position=(10, 50),
)
magtag.add_text(
    text_font="Arial-Bold-12.bdf",
    text_position=(10, 70),
)
magtag.set_text("Hello 1", auto_refresh=False)
magtag.set_text("Hello 2", 1, auto_refresh=False)
magtag.set_text("Hello 3", 2, auto_refresh=False)
magtag.set_text("Hello 4", 3)

print(magtag._fonts)
while True:
    pass

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.

I tested this successfully with the example script above. I had a different font on hand (arial 16) and I also added a few gc checks and I am seeing reduced memory usage with the new version.

Looks good to me. Thanks for this efficiency boost!

@makermelissa
Copy link
Collaborator Author

I'm gonna merge this in. It'll be moved to PortalBase when I get some refactor PRs merged, so it doesn't matter too much.

@makermelissa makermelissa merged commit d488d50 into adafruit:main Dec 5, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 7, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_SI7021 to 3.2.2 from 3.2.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_SI7021#19 from FoamyGuy/remove_busio

Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1306 to 2.10.0 from 2.9.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_SSD1306#53 from adamcandy/add-64x32-suppoort

Updating https://github.com/adafruit/Adafruit_CircuitPython_MagTag to 1.3.0 from 1.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#37 from anecdata/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#36 from ladyada/rotate
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#33 from adafruit/3.3-battery-voltage
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#32 from makermelissa/fontcache
@ladyada
Copy link
Member

ladyada commented Dec 7, 2020

verified that its about 50% faster now!

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.

3 participants