Skip to content

[gno] synchronous garbage collection #266

@jaekwon

Description

@jaekwon

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions