Skip to content

Conversation

@ltzmaxwell
Copy link
Contributor

@ltzmaxwell ltzmaxwell commented Apr 21, 2025

rebase to master. some issue to be resolved.

jaekwon and others added 2 commits April 21, 2025 12:45
...

Readonly is a property of TypedValue, rather than ReadonlyValue wrapper

fix tests

Machine.IsReadonly() also checks realm mismatch

nil interface is undefined

fix IsReadonly to use IsImmutable; half of convert check done

enable second opconvert check

...

...

first commit of interrealm_withswitch

fix zrealm_crossrealm11.gno test

intermediate

fix tests...

fix gnovm tests

...

heapitems_for_3693

update tests

fix heap return issues

...

cleanup and fixes

heap item all package vars

update golden tests

a funcvalue is an object; a func closure has no parent; find heap captures fix

update golden tests

fix one example test

update golden tests

fix script tests

add gno-memory-model

replace IsUndefined(); remove defaultValue() for safety

Add interrealm spec

add note on closures

update gno-interrealm.gno

replace callerat with current/previous realm()

borrrow realm -> switchrealm() test

borrow test; fix tests

fix gnolang#4019

fix stdlibs/std tests

initial implementation of GC

make it work

save

debug

fixup

save

add todo

package value size

metric shallowly

naive gas comsumption

gc benchmark init

fixup

fixup

fixup

simplify

fixup

fixup

txtar gas consumption

fixup

fmt

fixup

save

save

fixup

revert benchmark change

remove unused

fix test

add comment;update const;fix test

fmt

fixup

revert

clean

fixup

fixup

fixup

fixup

string value based

revert to array base

clean

fixup

fixup

correct string allocation

fixup

fix comment

clear unused store

gc callback

revert string value

fix after rebase

optimize

add comment
@ltzmaxwell ltzmaxwell marked this pull request as draft April 21, 2025 05:07
@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Apr 21, 2025
@ltzmaxwell ltzmaxwell changed the title feat(gnovm): garbage collector WIP feat(gnovm): garbage collector Apr 21, 2025
@Gno2D2 Gno2D2 requested review from a team April 21, 2025 05:07
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Apr 21, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: ltzmaxwell/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@jaekwon
Copy link
Contributor

jaekwon commented Apr 23, 2025

Linking the previous PR for comments: #3789

@ltzmaxwell ltzmaxwell marked this pull request as ready for review April 24, 2025 13:30
@ltzmaxwell ltzmaxwell changed the title WIP feat(gnovm): garbage collector feat(gnovm): garbage collector Apr 24, 2025
@codecov
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 55.49451% with 162 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/garbage_collector.go 47.08% 124 Missing and 21 partials ⚠️
gnovm/pkg/gnolang/alloc.go 76.81% 12 Missing and 4 partials ⚠️
gnovm/pkg/gnolang/realm.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ltzmaxwell
Copy link
Contributor Author

ltzmaxwell commented Apr 27, 2025

should also count m.Values?

// -----------------------------------------------

func (pv *PackageValue) GetShallowSize() int64 {
return allocPackage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type PackageValue struct {
	ObjectInfo
	FBlocks    []Value  //  Should we count this in the shallow size as well
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm technically yes, FNames and FBlocks, and their string sizes... we could do this here with _allocValue and _allocName, or do it in a separate PR. The strings we can re-count each time we see them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added here: 553a5e0


// Only count for closures.
func (fv *FuncValue) GetShallowSize() int64 {
return allocFunc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type FuncValue struct {
	ObjectInfo
	Captures   []TypedValue `json:",omitempty"`  //  Should we count this in the shallow size as well
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch—thank you for pointing that out. I agree it should be counted, but in the current implementation, these objects aren't allocated by the allocator (similar to m.Values).

We might optimize this later, to ensures the GC only recalculates previously allocated objects. otherwise the results would become inconsistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that we don't account for these during doOpFuncLit(), but that's a separate issue.
We should still count these, and even assume that each one of these have inside a HeapItemValue for simplicity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah definitely. the reason I planned doing this (and the one above) after this PR is that, there potentially can be some weird behavior, that the GC calculation process exceeds the maxBytes itself, because it counts some extra objects sizes which are not allocated previously. of course, this is quite an unusual case.

it's still ok to do it here since luckily we already have the logic to handle this.

also agreed with the idea described below to ensure strict correctness.

@jaekwon
Copy link
Contributor

jaekwon commented Apr 28, 2025

I wish we could write something that collects GC'd objects with ref zero from realm finalization, e.g. into Alloc or some struct, and basically run GC to calculate sizes without actually removing anything; The purpose is to see whether the allocation bytes from runtime is actually identical to what is calculated during GC by adding both non-GC remaining objects and GC'd objects together. Whenever there is a difference in the numbers, means we are missing some allocation step, or the GC is not iterating on something.

And then, we can also add tests to ensure that objects once put into the GC pile (those appended to Alloc for testing purposes as described in the previous paragraph), their GCCycle never changes, because the GC should never see them again.

This should be its own Issue to work on after this gets merged; it could be something to work on after the beta launch.

@ltzmaxwell
Copy link
Contributor Author

I wish we could write something that collects GC'd objects with ref zero from realm finalization, e.g. into Alloc or some struct, and basically run GC to calculate sizes without actually removing anything; The purpose is to see whether the allocation bytes from runtime is actually identical to what is calculated during GC by adding both non-GC remaining objects and GC'd objects together. Whenever there is a difference in the numbers, means we are missing some allocation step, or the GC is not iterating on something.

Yeah, assert that sum == remained + GC'd.

And then, we can also add tests to ensure that objects once put into the GC pile (those appended to Alloc for testing purposes as described in the previous paragraph), their GCCycle never changes, because the GC should never see them again.

👍

This should be its own Issue to work on after this gets merged; it could be something to work on after the beta launch.

OK.

@jaekwon jaekwon merged commit d37bc65 into gnolang:master Apr 29, 2025
64 of 70 checks passed
jaekwon added a commit that referenced this pull request May 1, 2025
rebase to master. some issue to be resolved.

---------

Co-authored-by: jaekwon <[email protected]>
stefann-01 pushed a commit to stefann-01/gno that referenced this pull request Jul 14, 2025
rebase to master. some issue to be resolved.

---------

Co-authored-by: jaekwon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants