Compilation and RAM usage FAQ

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Compilation and RAM usage FAQ

Post by jickster » Fri Dec 08, 2017 3:20 pm

Conceptually, why does a large script run out of RAM when it is compiled?

What is the relative ratio of usage of RAM (heap vs stack)?

Codewise, which part of the code causes RAM to be depleted (and is it heap vs stack)?

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Compilation and RAM usage FAQ

Post by jickster » Fri Dec 08, 2017 3:26 pm

If I run one line (or block) at a time of a `.py` via the REPL API (as in pyexec.c:pyexec_raw_repl()), will I eliminate the issue of running out of RAM during compilation?
i.e. for N lines in a `.py` file, will my peak RAM usage during compilation be more, less, or same if I feed in one line at a time vs compile the entire N lines at once?

I understand it'll be much slower but let's say I was running out of RAM during compilation and didn't care about speed.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Compilation and RAM usage FAQ

Post by jickster » Fri Dec 08, 2017 3:32 pm

If I compile the N lines separately, is it possible to stitch together the resulting bytecode returned by

Code: Select all

mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, emit_opt, is_repl);
into one mp_raw_code_t ?

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: Compilation and RAM usage FAQ

Post by chrismas9 » Fri Dec 08, 2017 10:57 pm

It's probably easier to pre-compile to mpy file on a PC

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Compilation and RAM usage FAQ

Post by jickster » Fri Dec 08, 2017 11:26 pm

chrismas9 wrote:It's probably easier to pre-compile to mpy file on a PC
It is but in some cases it’s not an option


Sent from my iPhone using Tapatalk

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Compilation and RAM usage FAQ

Post by pythoncoder » Sat Dec 09, 2017 7:19 am

@jickster Have you read http://docs.micropython.org/en/latest/p ... ained.html? In particular the section on the heap.
Peter Hinch
Index to my micropython libraries.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Compilation and RAM usage FAQ

Post by jickster » Sat Dec 09, 2017 1:59 pm

pythoncoder wrote:@jickster Have you read http://docs.micropython.org/en/latest/p ... ained.html? In particular the section on the heap.

Which sections answer my questions?


Sent from my iPhone using Tapatalk

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Compilation and RAM usage FAQ

Post by deshipu » Sat Dec 09, 2017 5:15 pm

jickster wrote:
Sat Dec 09, 2017 1:59 pm
Which sections answer my questions?
Read them then you will know.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Compilation and RAM usage FAQ

Post by jickster » Sat Dec 09, 2017 7:19 pm

deshipu wrote:
jickster wrote:
Sat Dec 09, 2017 1:59 pm
Which sections answer my questions?
Read them then you will know.
Where’s the answer to this?
jickster wrote:If I compile the N lines separately, is it possible to stitch together the resulting bytecode returned by

Code: Select all

mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, emit_opt, is_repl);
into one mp_raw_code_t ?


Sent from my iPhone using Tapatalk

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Compilation and RAM usage FAQ

Post by jickster » Sat Dec 09, 2017 7:20 pm

pythoncoder wrote:@jickster Have you read http://docs.micropython.org/en/latest/p ... ained.html? In particular the section on the heap.
Which section gives the answer to this question
jickster wrote:If I compile the N lines separately, is it possible to stitch together the resulting bytecode returned by

Code: Select all

mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, emit_opt, is_repl);
into one mp_raw_code_t ?


Sent from my iPhone using Tapatalk

Post Reply