krzema12 / kotlin-python

Python target for the Kotlin Programming Language. See https://github.com/krzema12/kotlin-python/tree/python-backend/python
https://discuss.kotlinlang.org/t/idea-python-backend/19852
47 stars 1 forks source link

Understand (and solve if trivial) MemoryErrors when using MicroPython #84

Open krzema12 opened 2 years ago

krzema12 commented 2 years ago

For example, when running e2e tests with micropython instead of python3, I got:

Traceback (most recent call last):
  File "python/e2e-tests/out/python-consumer.py", line 1, in <module>
  File "/home/piotr/repos/priv/kotlin-python/python/e2e-tests/out/compiled.py", line 12986, in <module>
MemoryError: memory allocation failed, allocating 26032 bytes

Looking at box tests report, >1000 tests fail with this reason. The good thing is that it's fairly reproducible: for a given box test, it always fails with such MemoryError.

My suspicion is that too much code is fed to micropython. Kotlin/Python doesn't do any Dead Code Elimination for now (to be done in #102), and the compiler output weights ~420 KiB.

LouisCAD commented 2 years ago

Quoting myself for reference:

Just thought about this: the issue might be about the implications of instantiating a NotImplementedError. Maybe it's worth trying to raise a custom thing/error/exception to see what causes this?

Isn't that related to the cost of building the stacktrace? I don't know how that works in Python, but I wouldn't be surprised to learn that it works differently in MicroPython, or that it's just not supported.