Skip to content

feat(gnovm): add gas for using println - #3949

Closed
omarsy wants to merge 14 commits into
gnolang:masterfrom
omarsy:fix/3819
Closed

omarsy wants to merge 14 commits into
gnolang:masterfrom
omarsy:fix/3819

Conversation

@omarsy

@omarsy omarsy commented Mar 16, 2025

Copy link
Copy Markdown
Member

closes: #3819

@Gno2D2

Gno2D2 commented Mar 16, 2025 •

Copy link
Copy Markdown
Collaborator

🛠 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)
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ 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: omarsy/gno)

Then

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

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🟢 User notJoon already reviewed PR 3949 with state APPROVED
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

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

@codecov

codecov Bot commented Mar 16, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.15742% with 178 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/values_string.go 65.31% 118 Missing and 2 partials ⚠️
gnovm/pkg/gnolang/types.go 72.53% 53 Missing ⚠️
gnovm/pkg/gnolang/machine.go 0.00% 2 Missing ⚠️
gnovm/pkg/gnolang/op_expressions.go 71.42% 2 Missing ⚠️
gnovm/pkg/test/filetest.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread gnovm/pkg/gnolang/machine.go Outdated
OpCPUReturnCallDefers = 78

/* Print */
OpCPUPrinln = 1

@odeke-em odeke-em Mar 16, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: "OpCPUPrintln" not "OpCPUPrinln"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

😮 thank you ^^

@omarsy
omarsy marked this pull request as ready for review March 20, 2025 19:37
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Mar 20, 2025
@omarsy

omarsy commented Mar 20, 2025

Copy link
Copy Markdown
Member Author

Maybe to close in favor of #3921.

@petar-dambovaliev

Copy link
Copy Markdown
Contributor

Maybe to close in favor of #3921.

Yes. i added you as a reviewer.

@notJoon notJoon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

remove: review/triage-pending flag

@notJoon notJoon removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Mar 26, 2025
Comment thread gnovm/pkg/gnolang/machine.go Outdated
Comment on lines +1143 to +1145
/* Print */
OpCPUPrintln = 1
OpCPUPrint = 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you get this information from benchops, rather than just assuming 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you know how to calculate the related gas with this ?

@ltzmaxwell ltzmaxwell Aug 7, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

like benchmark other OpCodes to calculate this.
however i'm good with a "guess value" here within this PR. Since there are some other places with the same issue, ie GC.
Eventually, we need a comprehensive benchmark after to fulfill all of these.

@thehowl

thehowl commented Apr 8, 2025

Copy link
Copy Markdown
Member

Closing in favour of #3921, apologies

@thehowl thehowl closed this Apr 8, 2025
@thehowl thehowl reopened this May 15, 2025
@github-project-automation github-project-automation Bot moved this from Done to In Progress in 💪 Bounties & Worx May 15, 2025
@thehowl

thehowl commented May 15, 2025

Copy link
Copy Markdown
Member

Seeing as petar is no longer working on #3921, do you mind picking up work here @omarsy?

Sorry for the back and forth :)

@omarsy

omarsy commented May 15, 2025

Copy link
Copy Markdown
Member Author

Seeing as petar is no longer working on #3921, do you mind picking up work here @omarsy?

Sorry for the back and forth :)

Yes I can have a look for this issue

@github-actions github-actions Bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label May 22, 2025
@omarsy
omarsy marked this pull request as ready for review June 8, 2025 19:39
fmt.Fprintf(builder, " %s(%d) %s\n", gens, gen, pv.PkgPath)
} else {
bsi := b.StringIndented(" ")
bsi := b.StringIndented(NewStringBuilderWithGasMeter(m.GasMeter), " ")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why use metering only in some cases here and not replace the builder type with a metered builder?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes right we can use same builder

@ltzmaxwell ltzmaxwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

get start reading and thinking

WriteString(s string) (int, error)
WriteByte(c byte) error
String() string
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this necessary? at least it should not be here in values.go

type Value interface {
assertValue()
String() string // for debugging
WriteString(builder Builder) Builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks odd

"github.com/gnolang/gno/tm2/pkg/store"
)

type StringBuilderWithGasMeter struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
type StringBuilderWithGasMeter struct {
type MeteredStringBuilder struct {

strings.Builder
}

func NewStringBuilderWithGasMeter(gasMeter store.GasMeter) *StringBuilderWithGasMeter {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
func NewStringBuilderWithGasMeter(gasMeter store.GasMeter) *StringBuilderWithGasMeter {
func NewMeteredBuilder(gasMeter store.GasMeter) *MeteredStringBuilder{

@ltzmaxwell

ltzmaxwell commented Aug 7, 2025 •

Copy link
Copy Markdown
Contributor

there are several PRs all related to gas consumption: for value stringer, for allocation, for frameSize? etc. will come back later and read these together.

@omarsy

omarsy commented Aug 7, 2025

Copy link
Copy Markdown
Member Author

there are several PRs all related to gas consumption: for value stringer, for allocation, for frameSize? etc. will come back later and read these together.

Yes, part of this PR will be fixed by #4546. I will remove the gas calculation during stringification and focus on the gas CPU consumption caused by printing.

@Kouteki

Kouteki commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Replaced by #4705

@omarsy

omarsy commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

Replaced by #4705

@omarsy omarsy closed this Sep 18, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in 💪 Bounties & Worx Sep 18, 2025
thehowl pushed a commit that referenced this pull request Oct 10, 2025
alternative to #3949

**Native Benchmark**
```
op,avg_time,avg_size,time_stddev,count
NativePrint_1,3742,0,761,5999
NativePrint_1000,4267,0,4088,5997
NativePrint_10000,5617,0,239,5995
```

**OP Code Benchmark**
```
op,avg_time,avg_size,time_stddev,count
OpAdd,48,0,61,1999
OpAddAssign,141,0,229,1000
OpArrayLit,237,0,616,5001
OpArrayType,154,0,62,7
OpAssign,156,0,285,4001
OpBand,49,0,54,1000
OpBandAssign,95,0,60,1000
OpBandn,50,0,178,1000
OpBandnAssign,100,0,294,1000
OpBinary1,52,0,129,3002
OpBody,103,0,349,18001
OpBor,47,0,44,1000
OpBorAssign,89,0,57,1000
OpCall,649,0,5239,17999
OpCallDeferNativeBody,77,0,60,1001
OpCallNativeBody,323,0,1046,5000
OpChanType,104,0,21,2
OpCompositeLit,105,0,614,7000
OpConvert,111,0,284,1001
OpDec,89,0,88,2001
OpDefer,292,0,6233,3001
OpDefine,197,0,904,14999
OpEql,105,0,118,1999
OpEval,64,0,253,18321
OpExec,45,0,62,18002
OpFieldType,155,0,71,39
OpForLoop,59,0,57,2000
OpFuncLit,282,0,1265,3001
OpFuncType,183,0,1022,3056
OpGeq,49,0,47,1000
OpGtr,63,0,225,2000
OpHalt,21,0,70,36514
OpIfCond,94,0,142,1999
OpInc,106,0,188,3000
OpIndex1,114,0,241,3001
OpIndex2,189,0,341,1000
OpInterfaceType,241,0,274,46
OpLand,59,0,178,2001
OpLeq,52,0,77,1000
OpLor,67,0,122,1000
OpLss,45,0,77,2999
OpMapLit,742,0,2287,1000
OpMapType,131,0,261,1006
OpMul,52,0,103,1000
OpMulAssign,99,0,145,1000
OpNeq,56,0,21,1000
OpPanic2,44,0,54,1000
OpPopBlock,30,0,57,21496
OpPopFrameAndReset,40,0,54,2000
OpPopResults,23,0,41,4000
OpPopValue,26,0,34,2999
OpPrecall,267,0,899,18000
OpQuo,143,0,246,1000
OpQuoAssign,213,0,345,1000
OpRangeIter,236,0,636,2000
OpRangeIterArrayPtr,57,0,59,1000
OpRangeIterMap,67,0,115,1000
OpRangeIterString,91,0,139,1000
OpRef,239,0,859,2000
OpRem,137,0,425,1000
OpRemAssign,170,0,252,1000
OpReturn,68,0,106,5000
OpReturnCallDefers,375,0,1182,3001
OpReturnFromBlock,76,0,119,17999
OpReturnToBlock,68,0,210,1001
OpSelector,103,0,203,1000
OpShl,63,0,330,1000
OpShlAssign,111,0,98,1000
OpShr,59,0,124,1000
OpShrAssign,108,0,180,1000
OpSlice,249,0,874,1000
OpSliceLit,443,0,1529,2000
OpSliceLit2,612,0,1396,1000
OpSliceType,172,0,104,15
OpStar,117,0,194,2000
OpStructLit,371,0,977,1999
OpStructType,361,0,226,3
OpSub,46,0,60,1000
OpSubAssign,119,0,183,1000
OpSwitchClause,91,0,418,1000
OpSwitchClauseCase,98,0,109,1000
OpTypeAssert1,618,0,577,1000
OpTypeAssert2,421,0,440,1000
OpTypeDecl,147,0,90,1003
OpTypeSwitch,91,0,88,1000
OpUneg,59,0,88,1000
OpUnot,34,0,64,1000
OpUpos,26,0,62,1001
OpUxor,43,0,17,1000
OpValueDecl,166,0,257,4001
OpVoid,26,0,59,36515
OpXor,52,0,48,1000
OpXorAssign,105,0,188,1000
```

---------

Co-authored-by: ltzmaxwell <ltz.maxwell@gmail.com>
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.

Gas for using println