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

It is not micro #2

Open
petrkr opened this issue Mar 21, 2023 · 2 comments
Open

It is not micro #2

petrkr opened this issue Mar 21, 2023 · 2 comments

Comments

@petrkr
Copy link

petrkr commented Mar 21, 2023

On ESP32 without external PSRAM it even does not imports. It will ate whole free memory

Traceback (most recent call last):
  File "main.py", line 2, in <module>
  File "/lib/meterbus/__init__.py", line 21, in <module>
  File "/lib/meterbus/telegram_control.py", line 1, in <module>
  File "/lib/meterbus/telegram_body.py", line 3, in <module>
  File "/lib/meterbus/telegram_variable_data_record.py", line 1, in <module>
MemoryError: memory allocation failed, allocating 136 bytes

Simple example just

from machine import UART, Pin
import meterbus.serial
import time
import meterbus

ser = UART(1, 2400, bits=8, parity=0, stop=1,  tx=4, rx=36)

would be nice to optimize it for low memory environments too to make it micro

also tried even simple import

>>> gc.mem_free()
101488
>>> gc.collect()
>>> gc.mem_free()
103280
>>> import meterbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/meterbus/__init__.py", line 21, in <module>
  File "/lib/meterbus/telegram_control.py", line 1, in <module>
  File "/lib/meterbus/telegram_body.py", line 3, in <module>
  File "/lib/meterbus/telegram_variable_data_record.py", line 1, in <module>
MemoryError: memory allocation failed, allocating 640 bytes
@petrkr
Copy link
Author

petrkr commented Mar 21, 2023

In case if I will precompile mpy_decimal to mpy, I am able to import, but not too much memory left, that will not be useable for SSL connections, where is atleast 30-40kB needed

>>> import meterbus
>>> gc.mem_free()
22496
>>> gc.collect()
>>> gc.mem_free()
26288

@petrkr
Copy link
Author

petrkr commented Mar 21, 2023

after precompile to mpy it just raise 1kB

>>> gc.collect()
>>> import meterbus
>>> gc.mem_free()
25728
>>> gc.collect()
>>> gc.mem_free()
27536

I barely go through code, there are lot of unsused / reserved index, which can be reduced to just unsupported in some logic in code, do not need load to mem 100 lines of "reserved" dictionaries

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