Skip to content

vm: Don't unconditionally allocate state on stack, do that only if needed. #641

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

Merged
merged 2 commits into from
Jun 1, 2014

Conversation

pfalcon
Copy link
Contributor

@pfalcon pfalcon commented May 31, 2014

This makes sure that only as much stack allocated as actually used, reducing
stack usage for each Python function call.

@pfalcon
Copy link
Contributor Author

pfalcon commented May 31, 2014

This addresses point 3 of #640 (comment). Unfortunately, this saves only 48 bytes of original 480 (10%).

@pfalcon
Copy link
Contributor Author

pfalcon commented May 31, 2014

Additional commit to start addressing point 1.

Paul Sokolovsky added 2 commits May 31, 2014 18:19
…eded.

This makes sure that only as much stack allocated as actually used, reducing
stack usage for each Python function call.
This improves stack usage in callers to mp_execute_bytecode2, and is step
forward towards unifying execution interface for function and generators
(which is important because generators don't even support full forms
of arguments passing (keywords, etc.)).
@dpgeorge
Copy link
Member

I'll need to review this carefully.

Personally, I'd go for much lower hanging fruit to begin with:

  1. Allow mp_call_function_n_kw to do a proper tail call by not having the check on res. There is only 1 case where res might be NULL (MP_OBJ_NULL actually), so check that explicitly in that case (and enforce the rule that ->call must never return MP_OBJ_NULL).
  2. mp_execute_bytecode is only called in one place, so copy it into that function to eliminate the call.

@pfalcon
Copy link
Contributor Author

pfalcon commented May 31, 2014

I tested it with testsuite and asyncio_micro server under load, so I'm pretty sure the patch is correct, but it's indeed would be nice if you gave it independent review.

mp_execute_bytecode is only called in one place, so copy it into that function to eliminate the call.

Well, that's something what I have in mind, but I probably approach it from somewhat different side. So, what prompted me to work on this is not really a stack usage, but the fact that generators still don't support _args, *_kwargs, etc. And indeed, what should be gone is mp_execute_bytecode(), and flow should be: client code which wants to call a function allocates a state array (either on stack or heap), then fills in state array with args (via a function call), then calls what's currently mp_execute_bytecode2().

But that's not low-hanging fruit at all, but introduction of mp_code_state structure is a way towards that ;-).

@dpgeorge
Copy link
Member

dpgeorge commented Jun 1, 2014

Okay, this is very nice.

@dpgeorge dpgeorge merged commit b4ebad3 into micropython:master Jun 1, 2014
@dpgeorge
Copy link
Member

dpgeorge commented Jun 1, 2014

It even reduced code size! (On stmhal by about 80 bytes, and also unix port, but strangely bare-arm went up by 500 bytes...).

@pfalcon pfalcon deleted the vm-alloca branch January 4, 2015 00:52
tannewt added a commit to tannewt/circuitpython that referenced this pull request Feb 27, 2018
…bsolete_drivers

Remove obsolete peripheral drivers in esp module
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

Successfully merging this pull request may close these issues.

2 participants