Reducing memory footprint by using _naming for purely internal constants #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While preparing some potential fixes for review I realized that most prospective fixes will increase memory usage a bit.
After some discussions in the
circuitpython-dev
Discord channel with danh I tried applying leading-underscore naming to the slew of purely internal constants in the main driver file.To see if this actually made a difference, I did some basic memory usage testing using a script I quickly put together. Its definitely not scientific - there are a bunch of other things that could be impacting memory usage - but at the very least it should provide some rough indication of whether this fix is worth the effort of submitting a PR. 😄
The table below shows the increase in memory usage from tests with four different versions of the library.
mpy
size20211114
mpyThe compiled file size dropped by more than 10%, which could be handy on some more limited boards. The memory usage savings weren't as strong but a 5% memory footprint reduction for just adding some underscores ain't bad.