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

Automatically growing the stack #4344

Closed
tuzz opened this Issue May 22, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@tuzz

tuzz commented May 22, 2016

Hello, thanks for a great project.

I'm using the -s ALLOW_MEMORY_GROWTH=1 setting when running a scientific program and it works great. I can see that the heap space increases as expected. However, the program runs out of stack space and I'm wondering if it's possible to automatically grow this too?

I've tried setting a bigger stack value, but eventually the program eats through it and I'd rather keep the stack size down for simple tasks.

Many thanks.

@kripken

This comment has been minimized.

Owner

kripken commented May 22, 2016

This is not currently possible. Memory growth replaces the entire ArrayBuffer with a new bigger one, which keeps all pointers still valid (they are just indexes). But the stack is a specific area inside of memory. Growing it by replacing it would make existing pointers invalid.

This could be done by allowing split stacks, which I think LLVM has some support for, but I'm not sure if it's complete, and it would also require runtime stuff on our side, which we don't have yet.

It's probably best to see where your app is using so much stack, and if it's possible to make it use less (e.g. by turning recursion into a manual stack).

@tuzz

This comment has been minimized.

tuzz commented May 22, 2016

Thanks for your prompt response.

In this case, I didn't write the application and so I wouldn't know how to modify the source to be less aggressive on the stack. I did manage to find a solution in the end which basically involved letting it run out of stack/heap space and then reinitializing with higher values. I had to make a few small changes to the generated code for this to work and the code that wraps this is quite involved, but I'm happy to share more details if anyone's interested.

The gist of it is here: https://github.com/tuzz/sentient.js/commit/2d5c3987d64c0e327d585f198dd6b81070c878aa

I'll close this now as this is no longer an issue for me.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment