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

SetVsyncEnabled(false) + SetScreenClearedEveryFrame(false) consumes more CPU than expected on desktops #2890

Closed
5 of 11 tasks
hajimehoshi opened this issue Jan 23, 2024 · 2 comments

Comments

@hajimehoshi
Copy link
Owner

hajimehoshi commented Jan 23, 2024

Ebitengine Version

v2.6.4 and main (006f14a)

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

Go Version (go version)

go version go1.21.6 windows/arm64

What steps will reproduce the problem?

Run this program and see the CPU usage on the task manager:

package main

import (
	"sync"

	"github.com/hajimehoshi/ebiten/v2"
)

type Game struct {
	once sync.Once
}

func (g *Game) Update() error {
	return nil
}

func (g *Game) Draw(screen *ebiten.Image) {
}

func (g *Game) Layout(width, height int) (int, int) {
	return width, height
}

func main() {
	ebiten.SetScreenClearedEveryFrame(false)
	ebiten.SetVsyncEnabled(false)
	if err := ebiten.RunGame(&Game{}); err != nil {
		panic(err)
	}
}

What is the expected result?

The CPU usage should be low (less than 5% or so)

What happens instead?

The CPU usage was about 50%

Anything else you feel useful to add?

This was found at #2889 (CC @erexo)

Let's check Linux too.

@hajimehoshi hajimehoshi added this to the v2.6.5 milestone Jan 23, 2024
@hajimehoshi
Copy link
Owner Author

Even on macOS, this optimization doesn't work with OpenGL.

@hajimehoshi hajimehoshi changed the title SetVsyncEnabled(false) + SetScreenClearedEveryFrame(false) consumes more CPU than expected on Windows SetVsyncEnabled(false) + SetScreenClearedEveryFrame(false) consumes more CPU than expected on desktops Jan 23, 2024
@erexo
Copy link
Contributor

erexo commented Jan 24, 2024

thanks ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants