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

perf: for loop and if #2140

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

perf: for loop and if #2140

wants to merge 7 commits into from

Conversation

petar-dambovaliev
Copy link
Contributor

@petar-dambovaliev petar-dambovaliev commented May 17, 2024

solves this

Benchmarks

Master
BenchmarkIfStatement-10    	     238	   4967960 ns/op
BenchmarkForLoop-10    	          649	   1771728 ns/op

Current branch
BenchmarkIfStatement-10    	     366	   3316189 ns/op
BenchmarkForLoop-10    	         1143	    945930 ns/op

By avoiding the runtime type conversion, we can see that we almost doubled the performance of these statements.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label May 17, 2024
@petar-dambovaliev petar-dambovaliev marked this pull request as ready for review May 17, 2024 13:42
Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 49.12%. Comparing base (7d939a0) to head (93f7de0).
Report is 13 commits behind head on master.

Files Patch % Lines
gnovm/pkg/gnolang/preprocess.go 58.33% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2140      +/-   ##
==========================================
+ Coverage   49.01%   49.12%   +0.11%     
==========================================
  Files         576      576              
  Lines       77604    78288     +684     
==========================================
+ Hits        38040    38462     +422     
- Misses      36481    36698     +217     
- Partials     3083     3128      +45     
Flag Coverage Δ
gnovm 42.19% <58.33%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@petar-dambovaliev petar-dambovaliev changed the title perf: for loop perf: for loop and if May 17, 2024
@zivkovicmilos zivkovicmilos linked an issue May 17, 2024 that may be closed by this pull request
gnovm/pkg/gnolang/preprocess.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/preprocess.go Outdated Show resolved Hide resolved
Comment on lines +2501 to +2505
if isUntyped(xt) {
if t == nil {
t = defaultTypeOf(xt)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This block is useless, t is no longer used afterwards

@@ -2490,6 +2490,22 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative
}
}

func checkWithoutConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative bool) {
Copy link
Member

@thehowl thehowl May 29, 2024

Choose a reason for hiding this comment

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

I found there is a similar "optimised case" -- checkOrConvertIntegerType. What do you think of changing this function to something like this?

// like checkOrConvertType() but for bools (ie. for and if).
func checkOrConvertBoolType(store Store, last BlockNode, x Expr) {
	if cx, ok := x.(*ConstExpr); ok {
		convertConst(store, last, cx, BoolType)
	} else if x != nil {
		xt := evalStaticTypeOf(store, last, x)
		if xt.Kind() != BoolKind { /* panic... */ }
	}
}

I think this might push the performance improvement a bit further :)

@@ -245,6 +245,38 @@ func main() {
m.RunMain()
}

func BenchmarkForLoop(b *testing.B) {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of having these simply as part of the benchdata tests?

There is a loop.gno test already, there's one missing for loop+if that you added. You can also run them individually:

go test -bench Benchdata/loop -run=^$ ./gnovm/pkg/gnolang/

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, I understand now the benchmarks are about preprocessing, not execution. Can you clarify that in the name? Ie. BenchmarkPreprocessForLoop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: No status
Status: In Review
Development

Successfully merging this pull request may close these issues.

perf: make for loops and if statements faster
4 participants