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

RFC: RAM utilisation optimisations #14

Open
peterhinch opened this issue May 13, 2018 · 0 comments
Open

RFC: RAM utilisation optimisations #14

peterhinch opened this issue May 13, 2018 · 0 comments

Comments

@peterhinch
Copy link
Contributor

peterhinch commented May 13, 2018

This library works extremely well but there are potential optimisations for use on platforms with little RAM. My asynchronous GPS device driver implements these. The principal categories are as follows:

  • Replace the string addition operator with the format method (since Python strings are immutable the string addition operator causes needless allocations). This also reduces code size.
  • Use lists rather than tuples for bound variables which are updated, changing each element individually to avoid allocating a temporary tuple.
  • Have common _fix and _set_timestamp methods to avoid code duplication.
  • Replace string comparisons with integer comparisons and use the micropython.const function. This may be an optimisation too far for an existing library as it changes the API.

The first optimisation can substantially simplify the MTK_commands library. See this method for an example (implements update_sentences).

Clearly allocation can't be eliminated as floats are necessarily employed and satellite information is dynamic, but minimising it helps reduce RAM fragmentation.

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

No branches or pull requests

1 participant