micropython-mqtt icon indicating copy to clipboard operation
micropython-mqtt copied to clipboard

RFC The main branch

Open peterhinch opened this issue 1 year ago • 2 comments

@bobveringa I hope you had an enjoyable break.

I have given some thought to the changes on the read_allocate branch. I think, once you've ironed out any issues in your application, these should be merged. These are the main considerations.

  • Using a dynamically sized pre-allocated buffer for ._as_read substantially reduces allocations.
  • Copying of incoming messages is essential in the case of the event interface.
  • In the case of the callback interface copying should be the default, which can be overridden for special use cases. The defaults is to avoid breaking code; also because passing a memoryview can cause concurrency bugs if a callback launches tasks.
  • If we are to merge this we should consider some refactoring in an attempt to reduce RAM usage, especially in __init__.py.

Re refactoring, I suggest you watch this short video by Damien George on MicroPython optimisation. This will explain why MicroPython code tends to differ from "big iron" Python, notably in object naming. My main concern is __init__.py because of the use of V3.1.1 on ESP8266, which is extremely RAM-constrained. You might also want to consider these issues in mqtt_v5_properties.py.

Like all optimistion, this may be done late, once we have a solution that meets your needs.

peterhinch avatar Sep 04 '24 09:09 peterhinch