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

Consider a smaller stack size #427

Open
SuperFola opened this issue Aug 12, 2023 · 1 comment
Open

Consider a smaller stack size #427

SuperFola opened this issue Aug 12, 2023 · 1 comment
Assignees
Labels
ark/compiler Related to the compiler ark/virtual machine Related to the ark virtual machine enhancement New feature or request optimization ❗️ priority/medium

Comments

@SuperFola
Copy link
Member

The problem

Creating a VM requires creating an ExecutionContext, that holds a few important values, such as the stack for the VM, defined as a std::array<Value, VmStackSize>. As of today, sizeof(Value) returns 40B, and the stack size is set to 8192 ; creating a VM thus requires 327kB.

Some tidbits about the compiler

The compiler can handle stack cleaning (ie a (while true 1) won't trash the stack luckily), and also handles correctly self tail calls (something is in the works to handle generic tail calls).

Generic tail calls will require a new instruction, akin to JUMP but for pages, so that we can jump between functions. Development on this should start shortly after having integrated the new parser.

Questions and experiments

  • do we still need a stack THIS big?
  • how does it currently affects script startup?
    • similarly, how does this affects the use of (async foo arg...)?

Data will be needed on the optimal stack size and the average stack size for common scripts.

Final words

Even though this would change a critical part of the virtual machine, this can not be considered a breaking change as the stack is never exposed to the end user (nor to plugin authors).

@SuperFola SuperFola added enhancement New feature or request ark/virtual machine Related to the ark virtual machine ark/compiler Related to the compiler optimization ❗️ priority/medium labels Aug 12, 2023
@SuperFola SuperFola self-assigned this Aug 12, 2023
@SuperFola
Copy link
Member Author

Thinking back about it, that would break recursion-intensive scripts that currently work.

A single function call takes at least 2 slots on the stack, for the old IP and PP to jump back to (which are not needed in tail calls luckily).

Might have to experiment with a stack size of 4096, maybe 2048, but I wouldn't go lower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ark/compiler Related to the compiler ark/virtual machine Related to the ark virtual machine enhancement New feature or request optimization ❗️ priority/medium
Projects
Status: No status
Development

No branches or pull requests

1 participant