inmcm/micropyGPS

RFC: RAM utilisation optimisations

peterhinch opened this issue · 0 comments

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.