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: make for loops and if statements faster #2138

Open
petar-dambovaliev opened this issue May 17, 2024 · 0 comments · May be fixed by #2140
Open

perf: make for loops and if statements faster #2138

petar-dambovaliev opened this issue May 17, 2024 · 0 comments · May be fixed by #2140
Assignees
Labels
📦 🤖 gnovm Issues or PRs gnovm related

Comments

@petar-dambovaliev
Copy link
Contributor

petar-dambovaliev commented May 17, 2024

package test
func main() {
	for i:=0; i<10; i++ {
		println(i)
	}
}

For this code, we generate the following AST

file{
	package test;
	func main() {
		for i<VPBlock(1,0)> := (const (0 int));
			(const-type bool)(i<VPBlock(1,0)> < (const (10 int))); i<VPBlock(1,0)>++{
				(const (println func(xs ...interface{})()))(i<VPBlock(1,0)>)
		}
	}
}

AsValue() gets called too many times, for every loop iteration.
On every call, it allocates. This is possibly due to the preprocessor labeling the loop condition as an untyped bool.

@petar-dambovaliev petar-dambovaliev self-assigned this May 17, 2024
@petar-dambovaliev petar-dambovaliev added the 📦 🤖 gnovm Issues or PRs gnovm related label May 17, 2024
@petar-dambovaliev petar-dambovaliev changed the title perf: make for loops faster perf: make for loops and if statements faster May 17, 2024
@petar-dambovaliev petar-dambovaliev linked a pull request May 17, 2024 that will close this issue
@zivkovicmilos zivkovicmilos linked a pull request May 17, 2024 that will close this issue
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: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant