Skip to content

Change from library dependency to code to save 37K of memory #12

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 7 commits into from
May 26, 2020

Conversation

jimbobbennett
Copy link
Collaborator

@jimbobbennett jimbobbennett commented May 9, 2020

The Adafruit_hashlib library uses a lot of memory, 26K. The Azure IoT library uses the CircuitPython HMAC library, which uses this library, eating a total of 29K.

These libraries handle a number of different hashing sizes, but the Azure IoT library only needs 256. By bringing in the code for just this, we can save 18K in memory usage, which is substantial!

Also removed dependencies on Parse and Base64, importing just the bare minimum code needed.

Saves 37K in total.

Jim Bennett added 2 commits May 8, 2020 18:57
Doing this removes a dependency on Adafruit_hashlib saving 18K in memory usage
@jimbobbennett
Copy link
Collaborator Author

I'm still testing everything works, just wanted to raise this for visibility.

@jimbobbennett jimbobbennett changed the title Change from library dependency to code to same memory Change from library dependency to code to save 18K of memory May 9, 2020
@jimbobbennett jimbobbennett changed the title Change from library dependency to code to save 18K of memory Change from library dependency to code to save 37K of memory May 9, 2020
@jimbobbennett
Copy link
Collaborator Author

jimbobbennett commented May 9, 2020

Memory usage testing was done with this code:

gc.collect()
free_memory = gc.mem_free()

from adafruit_azureiot import IoTCentralDevice

gc.collect()
print("Used memory", free_memory - gc.mem_free())

@jimbobbennett jimbobbennett marked this pull request as ready for review May 9, 2020 19:50
@jimbobbennett
Copy link
Collaborator Author

All tested and ready for review.

@tannewt
Copy link
Member

tannewt commented May 11, 2020

Note that the gc.collect() is redundant because CircuitPython will automatically collect after every import.

@jimbobbennett jimbobbennett requested a review from brentru May 22, 2020 22:21
Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

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

Reviewed, lgtm!

@brentru brentru merged commit 2467f04 into adafruit:master May 26, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 27, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 4.0.0 from 3.5.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#38 from Flameeyes/fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT to 2.2.0 from 2.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_AzureIoT#12 from jimbobbennett/master

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