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

Creating coroutines creates 2 megabytes of garbage #304

Open
RisingSunStudios opened this issue Jan 20, 2022 · 2 comments
Open

Creating coroutines creates 2 megabytes of garbage #304

RisingSunStudios opened this issue Jan 20, 2022 · 2 comments

Comments

@RisingSunStudios
Copy link

RisingSunStudios commented Jan 20, 2022

Hi,

Ran into an issue where creating new coroutines is allocating 2 megs of garbage, when a new Processor() is created - easy to see by attaching the Unity CPU profiler.

Any suggestions?

@AdamFrisby
Copy link

Funnily enough I just had to patch this recently.

It's caused by the ValueStack and ExecutionStack FastStack values in Processor.cs -- this is because it is a fixed width stack with a default size of 131072 elements. You can (generally) safely reduce the total number of elements which helps reduce the garbage, but setting these stacks to use pooling is what ultimately you want to do.

If you follow CoroutineState (the enum) and look for where "Dead" is assigned, that's where you recycle the elements back into the pool.

@RisingSunStudios
Copy link
Author

Thank you for posting about this, that's awesome to know. I had moved away from using Moonsharp because of this issue but honestly didn't spend any time looking into it. Good to know it's now a valid option again!

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

No branches or pull requests

2 participants