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

ebiten: improve DrawImage memory usage #3145

Open
11 tasks
hajimehoshi opened this issue Oct 25, 2024 · 2 comments
Open
11 tasks

ebiten: improve DrawImage memory usage #3145

hajimehoshi opened this issue Oct 25, 2024 · 2 comments
Milestone

Comments

@hajimehoshi
Copy link
Owner

Operating System

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

What feature would you like to be added?

Now BenchmarkDrawImage takes too much memory like 4GB:

go test -bench=DrawImage -run=^$ -benchmem -memprofile mem.prof

The profiler says

Showing nodes accounting for 6360.44MB, 100% of 6361.44MB total
Dropped 25 nodes (cum <= 31.81MB)
Showing top 10 nodes out of 16
      flat  flat%   sum%        cum   cum%
 4705.71MB 73.97% 73.97%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*commandQueue).EnqueueDrawTrianglesCommand
 1023.99MB 16.10% 90.07%  1023.99MB 16.10%  github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*uint32sBuffer).alloc (inline)
  630.75MB  9.92%   100%   630.75MB  9.92%  github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*commandQueue).appendIndices (inline)
         0     0%   100%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2.(*Image).DrawImage
         0     0%   100%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2/internal/atlas.(*Image).DrawTriangles
         0     0%   100%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2/internal/atlas.(*Image).drawTriangles
         0     0%   100%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2/internal/buffered.(*Image).DrawTriangles
         0     0%   100%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*Image).DrawTriangles
         0     0%   100%  1023.99MB 16.10%  github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*commandQueue).prependPreservedUniforms
         0     0%   100%  6360.44MB   100%  github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*commandQueueManager).enqueueDrawTrianglesCommand

This can be an issue when we want to use BenchmarkDrawImage with -count=10.

Why is this needed?

No response

@hajimehoshi hajimehoshi added this to the v2.9.0 milestone Oct 25, 2024
@hajimehoshi
Copy link
Owner Author

I thought this would work simply:

	b.Cleanup(func() {
		img0.At(0, 0)
		img0.Deallocate()
		runtime.GC()
	})

However, -count=10 still accumulates memory usages and finally the test used 20GB memory... Hmm

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
@hajimehoshi and others