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

[gno] synchronous garbage collection #266

Open
jaekwon opened this issue Jun 27, 2022 · 1 comment
Open

[gno] synchronous garbage collection #266

jaekwon opened this issue Jun 27, 2022 · 1 comment
Assignees
Labels
in focus Core team is prioritizing this work 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@jaekwon
Copy link
Contributor

jaekwon commented Jun 27, 2022

Currently the memory allocator doesn't account for any GC freed objects.
That is, objects like large strings or arrays each count against the allocation limit, even for temporary objects that get thrown away after the scope of the function call.

func SomeFunction() {
    x := ""
    for i:=0; i<100; i++ {
        x += "."
    }
}

For example, the above variable x returned is 100 bytes long, but all the prior subsequent strings were also accounted for, from x length 1, 2, 3, .. to length 100. Even though all prior x's become garbage collected, gno's memory management is not yet that smart.

This is a feature request issue to add some kind of synchronous garbage collection mechanism to free up GC'd memory. This could happen between realm function call boundaries, or it could happen with some special system function call. Or maybe this is best solved with function comment directives.


update

Garbage collection can be implemented synchronously upon memory alloc failure (before it returns failure) to scan all stack and block local variables to see what is still alive (and then decrement the total allocated number accordingly).

Two points:

  • If there is still not enough memory, there needs to be a second check where we panic out because GC couldn't save us.
  • GC itself should cost some meaningful deterministic gas amount.
  • Without GC cost, one can craft a program that ends up running GC on repeat, and can be very expensive.
@jaekwon jaekwon self-assigned this Jun 27, 2022
@jaekwon jaekwon changed the title GNO2: synchronous garbage collection [gno] synchronous garbage collection Jan 5, 2023
@jaekwon jaekwon removed their assignment Jun 2, 2023
@jaekwon
Copy link
Contributor Author

jaekwon commented Jun 2, 2023

clearing this just so anyone ambitious and familiar with the gno VM can try their hand at implementing.
please definitely get my feedback with some high level spec before actual implementation.
add me as reviewer in the PR.

@zivkovicmilos zivkovicmilos linked a pull request Oct 29, 2024 that will close this issue
@Kouteki Kouteki moved this from Triage to In Progress in 🧙‍♂️gno.land core team Nov 18, 2024
@Kouteki Kouteki added 📦 🤖 gnovm Issues or PRs gnovm related in focus Core team is prioritizing this work labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in focus Core team is prioritizing this work 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Core
Status: In Progress
Development

Successfully merging a pull request may close this issue.

6 participants