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

feat(gnovm): fill in 3779, the gc PR #3789

Open
wants to merge 38 commits into
base: dev/jae/gc
Choose a base branch
from

Conversation

ltzmaxwell
Copy link
Contributor

@ltzmaxwell ltzmaxwell commented Feb 19, 2025

This PR is trying to complete the work outlined in #3779 .

It completes the visit logic and introduces benchmarking and gas consumption tracking.

@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Feb 19, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Feb 19, 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):

No automated checks match this pull request.

☑️ 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
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

Sorry, something went wrong.

@Kouteki Kouteki added this to the 🚀 Mainnet beta launch milestone Feb 24, 2025
@Kouteki Kouteki requested a review from jaekwon February 25, 2025 13:39
@ltzmaxwell ltzmaxwell marked this pull request as draft February 25, 2025 15:20
@ltzmaxwell ltzmaxwell changed the title WIP: feat(gnovm): fill in gc feat(gnovm): fill in 3779, the gc PR Mar 3, 2025
@ltzmaxwell ltzmaxwell marked this pull request as ready for review March 3, 2025 09:01
// stop metric before next visit.
if bm.GCEnabled {
bm.StopGCCode()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to stop it before the next visit?
isn't it all just visits, all continuously GC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed benchmark and planned for future.

// Add object size to alloc.
size := o.GetShallowSize()
alloc.visitCount++ // count for gas calculation

alloc.Allocate(size)
// Stop if alloc max exceeded.
maxBytes, curBytes := alloc.Status()
if maxBytes < curBytes {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this really happen? GC usually occurs at a critical point, meaning that before this allocation, the total number of bytes hasn’t exceeded maxBytes. So during the recalculation process, the calculated result should not exceed the last crossing point, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see comment.

Comment on lines 75 to 78
type StringValue struct {
isNewBase bool // if the underlying data is new allocated or not.
Base *SliceValue
}
Copy link
Contributor Author

@ltzmaxwell ltzmaxwell Mar 16, 2025

Choose a reason for hiding this comment

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

This provides a method for handling string memory reuse and reallocation

e.g..

// MAXALLOC: 100000000
 package main

 import "runtime"

 var s = "hello world" // allocated in preprocess.

 func main() {
 	s += "!" // underlying array re-allocated in runtime
 	s1 := s  //  another string value, underlying array stays unchanged.
 	runtime.GC()
 	println("MemStats: ", runtime.MemStats())
 }

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: In Review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants